Java Reference
In-Depth Information
LISTING 14-6 (continued)
<h1>Welcome to our site</h1>
<h2>Click to see a <h:commandLink value="list of users"
You use the h:commandLink tag and reference the backing bean and the execute() method in
the action element. The execute() method is called directly from the JSF; it generates the user
list, returns the location of the view that will render the list, and then invokes the getUserList()
method and displays the user list. Listing 14‐7 demonstrates this.
LISTING 14 ‐7: The view that renders the model data
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
<title>List of users</title>
<h1>Our users are:</h1>
<ui:repeat value="#{listUsersAction.userList}" var="listusers">
<h:outputText value="#{listusers}" />
In the backing bean, the action class is referred to as listUsersAction starting in
lowercase, and the method getUserList() omits the word get . If a method starts with get , you can
omit it.
When you deploy this application, the index.xhtml view renders the link, which when clicked will
display a list of users as follows:
Our users are:
John Lennon
Ringo Starr
Paul McCartney
George Harrison
You have now successfully built an MVC‐style website using the latest features of Java EE 7.
Search WWH ::

Custom Search