j2ee_-_jsf_-_mastering_java_server_faces_-_wiley_-_2004

Page 282

Navigation, Actions, and Listeners

View Invoices page the application will rerender the Modify Invoice page, which will now display the error message. At this point the user is trapped, because repeated clicking of either the Save or the Cancel button will result in the same outcome. Fortunately, the cure is simple: just set the Cancel button’s immediate attribute to true: <h:commandButton id=”cancelButton” ... value=”Cancel” immediate=”true” action=”viewInvoices”/>

The other potential path in the navigational flow occurs when a user clicks Save, and the submitted values are converted and validated successfully. In this case, the Save button’s action will be evaluated. In the JSP shown in Listing 7.8, the Save button’s action is a method reference expression: <h:commandButton id=”saveButton” ... value=”Save” action=”#{modifyInvoicePage.save}”/>

The save() method shown in the listing for ModifyInvoicePage.java (Listing 7.11) uses a ValueBinding to get an instance of ConfirmInvoice Page, and then calls its setInvoice() method, passing the InvoiceBean as an argument. Finally, it returns confirmInvoice as its outcome. package com.wiley.masteringjsf.ch7ex2; import java.io.Serializable; import javax.faces.context.FacesContext; import javax.faces.el.ValueBinding; import com.sun.faces.util.Util; public class ModifyInvoicePage implements Serializable { /** The invoice bean managed by this page */ private InvoiceBean invoice; public ModifyInvoicePage() { } /**

Listing 7.11 ModifyInvoicePage.java. (continued)

255


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.