Java Reference
In-Depth Information
A real application would more than likely retrieve this information
from a relational database. To keep our example simple we are simply
populating the bean from new instances of RegistrationBean we
create on the fly.
Now we need to modify the JSP that will be invoked initially. When creating the
project, NetBeans automatically sets it up so that a JSP called welcomeJSF.jsp will be
invoked when we point the browser to our application's URL. We need to modify this
JSP so that it will invoke the populateList() method of our RegistrationBeanList
managed bean when navigating to the page we wrote earlier.
<h:commandLink value="Populate List"
action="#{RegistrationListController.populateList}" />
For brevity, we are only showing the relevant parts of the JSP. Our JSP will have
an <h:commandLink> tag used for navigation. <h:commandLink> is functionally
equivalent to <h:commandButton> , the main difference is that it is rendered as a
link as opposed to a button. The value of the value attribute of <h:commandLink>
is used to render the link text; its action attribute is used for navigation. In this
case we are using dynamic navigation. When using dynamic navigation, a value
binding expression is used as the value of the action attribute. This value binding
expression must resolve to a method that returns a String . The method must take
no arguments. When using dynamic navigation, the method that the value binding
expression resolves to may return different strings depending on its logic. We can
have a page navigate to different pages depending on the value returned by this
method. To do this we would have to add a <navigation-case> element for each
possible value that the method may return.
In our example, the populateList() method of the RegistrationListController
managed bean is invoked when a user clicks on the link. This method populates the
list that we will iterate through and returns the value of success .
Before we deploy our application, we need to define the navigation between our
two pages. Normally this is done by manually editing faces-config.xml. . However,
when using NetBeans, it can be done graphically in the NetBeans PageFlow editor as
explained earlier in this chapter.
Search WWH ::

Custom Search