background image

Referencing a Method

<< Referencing a Backing Bean Method | Value-Change Event >>
<< Referencing a Backing Bean Method | Value-Change Event >>

Referencing a Method

Referencing a Method That Performs Navigation
If your page includes a component (such as a button or hyperlink) that causes the application to
navigate to another page when the component is activated, the tag corresponding to this
component must include an action attribute. This attribute does one of the following
Specifies a logical outcome String that tells the application which page to access next
References a backing bean method that performs some processing and returns a logical
outcome String
The bookcashier.jsp page of the Duke's Bookstore application has a commandButton tag that
refers to a backing bean method that calculates the shipping date. If the customer has ordered
more than $100 (or 100 euros) worth of books, this method also sets the rendered properties of
some of the components to true and returns null; otherwise it returns receipt, which causes
the bookreceipt.jsp page to display. Here is the commandButton tag from the
bookcashier.jsp
page:
<h:commandButton
value=
"#{bundle.Submit}"
action=
"#{cashier.submit}" />
The action attribute uses a method expression to refer to the submit method of CashierBean.
This method will process the event fired by the component corresponding to this tag.
"Writing a Method to Handle Navigation" on page 404
describes how to implement the submit
method of CashierBean.
The application architect must configure a navigation rule that determines which page to access
given the current page and the logical outcome, which is either returned from the backing bean
method or specified in the tag. See
"Configuring Navigation Rules" on page 451
for information
on how to define navigation rules in the application configuration resource file.
Referencing a Method That Handles an Action Event
If a component on your page generates an action event, and if that event is handled by a backing
bean method, you refer to the method by using the component's actionListener attribute.
The chooselocale.jsp page of the Duke's Bookstore application includes some components
that generate action events. One of them is the NAmerica component:
<h:commandLink id=
"NAmerica" action="bookstore"
actionListener=
"#{localeBean.chooseLocaleFromLink}">
The actionListener attribute of this component tag references the chooseLocaleFromLink
method using a method expression. The chooseLocaleFromLink method handles the event of a
user clicking on the hyperlink rendered by this component.
Referencing a Backing Bean Method
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
371