Este contenido no está disponible en el idioma seleccionado.
4.5. State Manager API
JSF has an advanced navigation mechanism that lets you define navigation from view to view. In a web application, navigation occurs when a user changes from one page to another by clicking on a button, a hyperlink, or another command component. There is no switch mechanism between some logical states of the same view. For example, in Login/Register dialog, an existing user signs in with his user name and password, but if a new user attempts to register, an additional field (
Confirm) is displayed, and button labels and methods are changed when the user clicks the To register link:
Figure 4.7. Login Dialog
Figure 4.8. Register Dialog
RichFaces State API lets you easily define a set of states for pages, and properties for these states.
The
States class interfaces with a map, where the keySet defines the State name and the entrySet is a State map. The State map defines the properties, method bindings, or constant state variables of a key or object, where these values may change depending on the active State.
Figure 4.9. RichFaces State API
One of the most convenient features of the RichFaces State API is the ability to navigate between
States. The API implements changes in State through standard JSF navigation. When the action component returns an outcome, the JSF navigation handler (extended through the RichFaces State API) checks whether the outcome is registered as a State change outcome. If true, the corresponding State is activated. If false, standard navigation handling is called.
Implement the RichFaces State API like so:
- Register the State Navigation Handler and the EL Resolver in your
faces-config.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Register an additional application factory in the
faces-config.xml:... <factory> <application-factory>org.richfaces.ui.application.StateApplicationFactory</application-factory> </factory> ...
... <factory> <application-factory>org.richfaces.ui.application.StateApplicationFactory</application-factory> </factory> ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Register two managed beans in the
faces-config.xml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow One bean (config) defines and storesStateas seen in the following example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The second bean, with theorg.richfaces.ui.model.Statestype (state), contains the managed property states, which is bound to the firstconfigbean. - Next, use state bindings on the page, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To see complete example of the Login/Register dialog, see the RichFaces Live Demo.