Apple WebObjects 3.5 Tools And Techniques User Manual

Page 80

Advertising
background image

Chapter 3

Working With Dynamic Elements

80

the WOConditional’s contents are displayed. If

condition

is false (0), the contents

aren’t displayed.

condition

can be bound to a variable or to method that returns a Boolean value.

(WebScript and Objective-C use the constants

YES

and

NO

; Java uses

true

and

false

.)

To bind

condition

(or any other attribute that takes a Boolean) to a constant value,

enter

YES

or

NO

in the bindings Inspector.

To create a conditional, click

in the toolbar.

Note:

Any selected elements will be contained within the conditional.

To bind to a conditional, click a variable or method and drag to one of the
conditional’s outer icons. The Inspector appears, displaying the bindings for the
WOConditional, with the

condition

attribute selected by default. Complete the

binding by clicking Connect Variable, or choose a different attribute to bind.

There is a shortcut for binding the condition attribute. Drag from a key in the
object browser to the binding box in the conditional.

Sometimes, you want the equivalent of an “if-then-else” structure; that is, “if
the condition is true, display this text; if not, display this other text.” To
accomplish this, you can use the

negate

attribute. If

negate

is true, then the

contents of the conditional are displayed only if

condition

is false. To create an if-

then-else structure, do the following:

1. Create two WOConditionals.

2. Bind the

condition

attribute of both of them to the same variable or method.

3. Bind the

negate

attribute of the second one to

YES

(true).

By default,

negate

is false, so you do not explicitly need to bind the first

conditional’s negate attribute.

As with repetitions, you can “wrap” a conditional around a table row (see
“Repetitions”). When you do this, the conditional symbol doesn’t appear but
the row appears with a blue background.

Drag from the object browser to this box to bind the

condition attribute

without opening the Inspector. The binding appears inside the box.

Contents of the conditional display if
condition is true.

Drag from the object browser to here
to bind (opensthe Inspector).

Advertising