Associations and the current component – Apple WebObjects 3.5 User Manual

Page 84

Advertising
background image

Chapter 5

WebObjects Viewed Through Its Classes

84

Associations and the Current Component

A dynamic HTML element, such as a text field or a pop-up button, differs from
a static HTML element, such as a heading, in that its attributes can change over
a cycle of the request-response loop. These attributes can include values that
determine behavior or appearance (a “disabled” attribute, for instance), values
that users enter into a field, values that are returned from a method, and actions
to invoke when users click or otherwise activate the element. Each dynamic
element stores its attributes as instance variables of type WOAssociation (in
Java, Association). WOAssociation objects know how to obtain and set the value
they represent. They generally do this using key-value coding.

The key to a value can be represented as a sequence of keys separated by
periods. The resolution of a key by yielding its value makes possible the
resolution of the next key. For instance:

self.aRepetition.list.item

means that

self

(identifying the current component) has a WORepetition named

aRepetition

. The

list

key denotes the list of elements displayed by the

WORepetition, and the

item

is the key to the current item in that list. Keys

(including actions) are WOAssociations defined for each dynamic element. The
values for these keys are constants assigned in the

.wod

file, or they derive from

bindings to variables, to methods, or to entities retrieved through a
WODisplayGroup (for applications that access a database).

WOAssociation objects refer to the current component for the initial value of this
sequence. They get this object from the cycle’s WOContext object. Often the
current component is the request or response page of the cycle, but it can be a
reusable component embedded in a page, or even a component incorporated by
one of those subcomponents. See “Subcomponents and Component
References” (page 86) for more on this. WOContext stores the current
component on a stack, “pushing” and “popping” components onto and off of
the stack as necessary.

Depending on the phase of the request-response loop, a dynamic element uses
its WOAssociations to “pull” values from the request (that is, set its values to
what the user specifies) or to “push” its values onto the response page. When a
dynamic element that can respond to user actions (such as WOSubmitButton)
requests the value of its “action” WOAssociation, the appropriate action method
in the current component is invoked and the response page is returned.

The exchange of data through an association that binds an attribute of a parent
component to an attribute of a child component is two-way. This two-way
binding allows the synchronization of state between the two components.
Consider this declaration in

Main.wod

of the TimeOff example:

Advertising