img
. . . . . .
public ContactListBean newContactListBean() {
ContactListBean contactListBean = new ContactListBean();
contactListBean.setContacts(contactService.findAll());
return contactListBean;
}
}
The class is a simple POJO, too. We just define it as a Spring bean (by using the @Component
annotation), and Spring Web Flow will be able to locate it and execute the method when entering the
start state. As you can see, the method simply invokes the method from the service layer, stores the
contact lists into a new instance of the ContactListBean class, and then returns the instance. In the flow
definition, the returned object will be stored in the view scope variable, available to JSF when rendering
the response.
Note In Listing 18-9, the @Component annotation, rather than the @Controller annotation, is used. This is
because in this chapter we use Spring Web Flow to control the application flow, not Spring MVC's controller
classes. So, we just need to declare it as a trivial Spring bean implementing the list contact view.
Now we can implement the list contact view, which is the start state of the flow. Listing 18-10 shows
the code of the view (/WEB-INF/flows/contacts/list.xhtml).
Listing 18-10. The List Contact View
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/layouts/standard.xhtml">
<ui:define name="title">#{msg['application_name']}</ui:define>
<ui:define name="content">
<h:form>
<h:panelGrid columns="1">
<p:commandButton value="#{msg['label_contact_new']}" action="add"/>
<p:dataTable var="contact" value="#{contactListBean.contacts}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home