Java Reference
In-Depth Information
Line 10 : When the page is submitted, JSF will find the helloBean and set
the submitted name value via the setName() method. When hello.xhtml is
displayed, JSF will find the helloBean and display the name property value via its
getName () method.
Listing 6-3 illustrates the helloBean .
Listing 6-3. Managed Bean
1. package com.apress.jsf.helloworld;
2. import javax.faces.bean.ManagedBean;
3. import javax.faces.bean.SessionScoped;
4. import java.io.Serializable;
5.
6. @ManagedBean
7. @SessionScoped
8. public class HelloBean implements Serializable {
9.
10. private static final long serialVersionUID = 1L;
11.
12. private String name;
13.
14. public String getName() {
15. return name;
16. }
17. public void setName(String name) {
18. this.name = name;
19. }
20. }
Line 6 : A managed bean is a Java bean that is accessed from a JSF page. The
@ManagedBean annotation specifies the name by which an object of this class is
referenced in the JSF pages.
Line 7 : A managed bean must have a name and a scope. Session scope
signifies that the bean object is available for one user across multiple pages.
Note There are two annotations for naming a bean. @Named is the best choice with a Java EE 6 and newer
application server.
Like Struts and Spring MVC web applications, when you deploy a JSF web application
inside an application server, you need to provide a deployment descriptor file named web.xml .
Listing 6-4 shows this file. For the sake of brevity, the web-app declaration and the list of files in the
welcome-file-list are not completely shown.
 
 
Search WWH ::




Custom Search