servlets struts hibernate spring maven java
 

JSF Managed Bean



It is an unadulterated Java class which contains set of properties and set of getter, setter methods.

Following are the basic functions that overseen bean methods perform:

  • Validating a component's data
  • Handling an event terminated by a component
  • Performing processing to decide the following page to which the application must navigate

It additionally functions as model for JFS Framework.

JSF Managed Bean Example

  1. public class User {  
  2. private String name;  
  3. public String getName() {  
  4. return name;  
  5. }  
  6. public void setName(String name) {  
  7. this.name = name;  
  8. }   
  9. }  

You can use this bean by the following ways.

  1. By configuring into XML file.
  2. By using annotations.

Configuring Managed Bean using Annotations

  1. import javax.faces.bean.ManagedBean;  
  2. import javax.faces.bean.RequestScoped;  
  3.   
  4. @ManagedBean    // Using ManagedBean annotation  
  5. @RequestScoped  // Using Scope annotation  
  6. public class User {  
  7.     private String name;  
  8.     public String getName() {  
  9.         return name;  
  10.     }  
  11.     public void setName(String name) {  
  12.      this.name = name;  
  13. }  
  14. }  

The @ManagedBean annotation in a class automatically registers that class as a resource with the JavaServer Faces. Such a registered managed bean does not need managed-bean configuration entries in the application configuration resource file.







© Javacodegeeks © 2019 - 2019
All Right Reserved and you agree to have read and accepted our term and condition.

Python 3