CHAPTER 6: Component-Based Web Development Using JSF 2 281
- In the Invoke Application phase, the UICommand component checks whether
the button was clicked. If so, it triggers an action event, namely, the hello
action referenced in the action attribute, which tells the navigation handler to
look for the hello.xhtml page, and the JSF runtime enters the sixth phase:
Render Response. - FacesServlet creates a response component tree, and each component
renders itself as the JSF runtime goes through the corresponding JSF
tags. At the end of this phase, the state of the response is saved so that
FacesServlet can access it during the Restore View phase of subsequent
requests to the same page.
Managed Beans
A managed bean is a regular JavaBean class registered with JSF and managed by the JSF
framework and serves as the model for the UI component. The managed bean contains the getter
and setter methods, business logic, or a backing bean that is a bean that contains all the values of
the form. The managed beans are responsible for the following:
Synchronizing server-side data with components in the component tree
Processing business logic
Handling navigation between pages
The component is associated with a specific managed bean property or action by means of the
EL. As you saw in the Hello World application, you do not need to write any code to construct and
manipulate the HelloBean. The JSF runtime constructs the beans and accesses them. Managed
beans can be easily registered in a JSF configuration file (that is, faces-config.xml) or using
annotations.
Listing 6-5 illustrates registering a managed bean using XML configuration.
Listing 6-5. Registering a Managed Bean Using XML
Listing 6-6 illustrates registering a managed bean using an annotation.
Listing 6-6. Registering Managed Bean Using an Annotation
@ManagedBean
@SessionScoped
public class HelloWorld {
}