Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > WebObjects Developer's Guide


Table of Contents Previous Section

Binding Values to Dynamic Elements

In the previous 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. For example, you might define a component that displays relevant information about the application, including the date and time the application was started. It makes sense for the application object to store this date and time. Your component's .wod file would access it through 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 takeValueForKey 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 above component using key-value coding, WebObjects performs the following steps:

Here are the general rules for binding dynamic element attributes:

Note: Be aware that value = person.count will not work, as count is assumed to be a dictionary key.

Table of Contents Next Section