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.

See “Backing Beans” on page 307 for more general information on component binding.<br />

See “Referencing a Method That Performs Navigation” on page 369 for information on how to<br />

reference a backing bean method that performs navigation when a button is clicked.<br />

See “Writing a Method to Handle Navigation” on page 402 for more information on writing<br />

backing bean methods that handle navigation.<br />

Writing Properties Bound to Converters, Listeners, or<br />

Validators<br />

All of the standard converter, listener, and validator tags that are included with <strong>Java</strong>Server Faces<br />

technology support binding attributes that allow page authors to bind converter, listener, or<br />

validator implementations to backing bean properties.<br />

<strong>The</strong> following example from “Binding Converters, Listeners, and Validators to Backing Bean<br />

Properties” on page 367 shows a standard convertDateTime tag using a value expression with<br />

its binding attribute to bind the DateTimeConverter instance to the convertDate property of<br />

LoginBean:<br />

<br />

<br />

<br />

<strong>The</strong> convertDate property must therefore accept and return a DateTimeConverter object, as<br />

shown here:<br />

private DateTimeConverter convertDate;<br />

public DateTimeConverter getConvertDate() {<br />

...<br />

return convertDate;<br />

{<br />

public void setConvertDate(DateTimeConverter convertDate) {<br />

convertDate.setPattern("<strong>EE</strong><strong>EE</strong><strong>EE</strong><strong>EE</strong>, MMM dd, yyyy");<br />

this.convertDate = convertDate;<br />

}<br />

Writing Bean Properties<br />

Because the converter is bound to a backing bean property, the backing bean property is able to<br />

modify the attributes of the converter or add new functionality to it. In the case of the preceding<br />

example, the property sets the date pattern that the converter will use to parse the user’s input<br />

into a Date object.<br />

<strong>The</strong> backing bean properties that are bound to validator or listener implementations are written<br />

in the same way and have the same general purpose.<br />

Chapter 12 • Developing with <strong>Java</strong>Server FacesTechnology 387

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

Saved successfully!

Ooh no, something went wrong!