Binding values to dynamic elements – Apple WebObjects 3.5 User Manual

Page 35

Advertising
background image

Server-Side Dynamic Elements

35

Finally, the WOString element defines a

value

attribute, which specifies the

string you want displayed. This

value

attribute is bound to the

currentOption

variable, which is also bound to the

item

attribute of the WORepetition. As

you’ll recall,

currentOption

is updated with each iteration that the

WORepetition makes. So, for each item in the

allOptions

array (assigned to the

WORepetition’s

list

attribute), the WORepetition updates the

currentOption

variable to point to that item and then the WOString prints it on the page.

Binding Values to Dynamic Elements

In the CyberWind example, all of the dynamic elements are bound to
variables and methods from the component that contains them (the Main
component). It’s common to bind to variables and methods declared
directly in the current component; however, you can bind to any value that
the component can access.

This means, for instance, that you can bind to variables from the application
or session object because the WOComponent class declares two instance
variables,

application

and

session

, which point to the current application and the

current session. Look at CyberWind’s Footer component in WebObjects
Builder. This component displays, among other information, the date and
time the CyberWind application was started.This date is stored in the
application object, not in the Footer component. The Footer component’s

.wod

file contains this declaration:

UP_SINCE:WOString {value = application.upSince.description};

To retrieve a value from this binding, WebObjects uses key-value coding, a
standard interface for accessing an object’s properties either through
methods designed for that purpose or directly through its instance variables.
With key-value coding, WebObjects sends the same message
(

takeValue:forKey:

, or

takeValue

in Java) to any object it is trying to access. Key-

value coding first attempts to access properties through accessor methods
based on the key’s name.

For example, to resolve the binding for the WOString element in the
Footer component using key-value coding, WebObjects performs the
following steps:

It resolves the value for the

application

key by looking for a method named

application

in the component object.

In this case, WOComponent (Component in Java) defines the

application

method, which returns the WOApplication object (WebApplication in
Java).

Advertising