<evaluate expression="contactController.newContactBean()"
result="flowScope.contactBean"/>
</transition>
</view-state>
...
<view-state id="show" view="show.xhtml">
<on-entry>
<evaluate expression="contactController.showContact(flowRequestContext)"
result="viewScope.contact"/>
</on-entry>
<transition on ="back" to="start"/>
</view-state>
In Listing 18-11, the navigation to the contact show view and the show state was highlighted in bold.
Within the <transition> tag in the start state, a variable called contactId with the request scope was set
(based on the id of the contact of the selected row) and then transitioned to the show state.
In the show state, the ContactController.showContact() method is called, passing in an instance
of the org.springframework.webflow.execution.RequestContext interface; the result (the contact
object with the selected ID) is stored in a view scope variable called contact, and then the view
(show.xhtml) is rendered.
Listing 18-12 shows the implementation of the showContact() method.
Listing 18-12. Implementing the showContact() Method
package com.apress.prospring3.ch18.web.controller;
// Import statements omitted
@Component("contactController")
public class ContactController {
// Other code omitted
public Contact showContact(RequestContext context) {
Long id = context.getRequestScope().getLong("contactId");
logger.info("Selected contact id: {}", id);
return contactService.findByIdWithDetail(id);
}
}
In Listing 18-12, the method RequestContext.getRequestScope().getLong() is called to retrieve the
contactId variable, and then the method ContactService.findByIdWithDetail() is called, which will
load the contact with the hobbies for the contact. The returned Contact object is stored as a view scope
variable for rendering the show contact view.
Listing 18-13 shows the show contact view (webapp/WEB-INF/flows/contacts/show.xhtml).
Listing 18-13. The Show 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"
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home