background image

The commandButton Tag

<< The inputSecret Tag | Using Data-Bound Table Components >>
<< The inputSecret Tag | Using Data-Bound Table Components >>

The commandButton Tag

In addition to the tag attributes listed in
"Adding UI Components to a Page Using the HTML
Component Tags" on page 327
, the commandButton and commandLink tags can use these
attributes:
action
, which is either a logical outcome String or a method expression pointing to a bean
method that returns a logical outcome String. In either case, the logical outcome String is
used by the default NavigationHandler instance to determine what page to access when the
UICommand
component is activated.
actionListener
, which is a method expression pointing to a bean method that processes an
action event fired by the UICommand component.
See
"Referencing a Method That Performs Navigation" on page 371
for more information on
using the action attribute.
See
"Referencing a Method That Handles an Action Event" on page 371
for details on using the
actionListener
attribute.
Rendering a Button with the commandButton Tag
The bookcashier.jsp page of the Duke's Bookstore application includes a commandButton tag.
When a user clicks the button, the data from the current page is processed, and the next page is
opened. Here is the commandButton tag from bookcashier.jsp:
<h:commandButton value=
"#{bundle.Submit}"
action=
"#{cashier.submit}"/>
Clicking the button will cause the submit method of CashierBean to be invoked because the
action
attribute references the submit method of the CashierBean backing bean. The submit
method performs some processing and returns a logical outcome. This is passed to the default
NavigationHandler
, which matches the outcome against a set of navigation rules defined in the
application configuration resource file.
The value attribute of the preceding example commandButton tag references the localized
message for the button's label. The bundle part of the expression refers to the ResourceBundle
that contains a set of localized messages. The Submit part of the expression is the key that
corresponds to the message that is displayed on the button. For more information on
referencing localized messages, see
"Rendering Components for Selecting Multiple Values" on
page 345
. See
"Referencing a Method That Performs Navigation" on page 371
for information on
how to use the action attribute.
Rendering a Hyperlink with the commandLink Tag
The commandLink tag represents an HTML hyperlink and is rendered as an HTML <a> element.
The commandLink tag is used to submit an action event to the application. See
"Implementing
Action Listeners" on page 397
for more information on action events.
Adding UI Components to a Page Using the HTML Component Tags
The Java EE 5 Tutorial · September 2007
336