background image

Writing Backing Bean Methods

<< Writing the Tag Library Descriptor | The NavigationHandler >>
<< Writing the Tag Library Descriptor | The NavigationHandler >>

Writing Backing Bean Methods

<type>String</type>
</deferred-value>
</attribute>
</tag>
The name element defines the name of the tag as it must be used in the page. The tag-class
element defines the tag handler class. The attribute elements define each of the tag's attributes.
The formatPatterns attribute is the only attribute that the tag supports. The deferred-value
element indicates that the formatPatterns attribute accepts deferred value expressions. The
type
element says that the expression resolves to a property of type String.
Writing Backing Bean Methods
Methods of a backing bean perform application-specific functions for components on the page.
These functions include performing validation on the component's value, handling action
events, handling value-change events, and performing processing associated with navigation.
By using a backing bean to perform these functions, you eliminate the need to implement the
Validator
interface to handle the validation or the Listener interface to handle events. Also,
by using a backing bean instead of a Validator implementation to perform validation, you
eliminate the need to create a custom tag for the Validator implementation.
"Creating a
Custom Validator" on page 398"Creating a Custom Validator" on page 398
describes
implementing a custom validator.
"Implementing an Event Listener" on page 395
describes
implementing a listener class.
In general, it's good practice to include these methods in the same backing bean that defines the
properties for the components referencing these methods. The reason is that the methods might
need to access the component's data to determine how to handle the event or to perform the
validation associated with the component.
This section describes the requirements for writing the backing bean methods.
Writing a Method to Handle Navigation
A backing bean method that handles navigation processing, called an action method, must be a
public method that takes no parameters and returns an Object, which is the logical outcome
that the navigation system uses to determine what page to display next. This method is
referenced using the component tag's action attribute.
The following action method in CashierBean is invoked when a user clicks the Submit button
on the bookcashier.jsp page. If the user has ordered more than $100 (or 100 euros) worth of
books, this method sets the rendered properties of the fanClub and specialOffer components
to true. This causes them to be displayed on the page the next time the page is rendered.
Writing Backing Bean Methods
The Java EE 5 Tutorial · September 2007
404