10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Writing Bean Properties<br />

378<br />

<strong>The</strong> UI component’s tag binds the component’s value to a property using its value attribute and<br />

binds the component’s instance to a property using its binding attribute, as explained in<br />

“Binding Component Values and Instances to External Data Sources” on page 362. Likewise, all<br />

the converter, listener, and validator tags use their binding attributes to bind their associated<br />

implementations to backing bean properties, as explained in “Binding Converters, Listeners,<br />

and Validators to Backing Bean Properties” on page 367.<br />

To bind a component’s value to a backing bean property, the type of the property must match<br />

the type of the component’s value to which it is bound. For example, if a backing bean property<br />

is bound to a UISelectBoolean component’s value, the property should accept and return a<br />

boolean value or a Boolean wrapper Object instance.<br />

To bind a component instance, the property must match the component type. For example, if a<br />

backing bean property is bound to a UISelectBoolean instance, the property should accept and<br />

return UISelectBoolean.<br />

Similarly, in order to bind a converter, listener, or validator implementation to a property, the<br />

property must accept and return the same type of converter, listener, or validator object. For<br />

example, if you are using the convertDateTime tag to bind a DateTime converter to a property,<br />

that property must accept and return a DateTime instance.<br />

<strong>The</strong> rest of this section explains how to write properties that can be bound to component values,<br />

to component instances for the component objects described in “Adding UI Components to a<br />

Page Using the HTML Component Tags” on page 325, and to converter, listener, and validator<br />

implementations.<br />

Writing Properties Bound to ComponentValues<br />

To write a backing bean property bound to a component’s value, you must know the types that<br />

the component’s value can be so that you can make the property match the type of the<br />

component’s value.<br />

Table 12–1 lists all the component classes described in “Adding UI Components to a Page<br />

Using the HTML Component Tags” on page 325 and the acceptable types of their values.<br />

When page authors bind components to properties using the value attributes of the<br />

component tags, they need to ensure that the corresponding properties match the types of the<br />

components’ values.<br />

TABLE 12–1 Acceptable Types of Component Values<br />

Component AcceptableTypes of ComponentValues<br />

UIInput, UIOutput,<br />

UISelectItem, UISelectOne<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010<br />

Any of the basic primitive and numeric types or any <strong>Java</strong> programming<br />

language object type for which an appropriate Converter implementation<br />

is available.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!