Академический Документы
Профессиональный Документы
Культура Документы
www.icefaces.org
Managed Beans JSF allows users to design a complex tree of named POJO Beans Beans have a predetermined lifespan known as scope Beans can be defined using:
Managed Bean Creation facility (faces-config.xml) Java EE 5 annotations
Managed Beans also have a lifecycle which depends on their specified scope
www.icefaces.org
POJO Beans Application developers have full control over application design Full control gives you great flexibility in your design but it can also expose you to common design errors
www.icefaces.org
Bean Names Bean names uniquely identify the Bean within the context of the application Follow the same naming conventions as Java classes, mixed case starting with lower case Bean names can be defined in faces-config.xml
<managed-bean> <managed-bean-name> myBeanName </managed-bean-name> <managed-bean-class> org.mycompany.package.ClassName </managed-bean-class> ... </managed-bean>
www.icefaces.org
Bean Names JSF 2 introduces the @ManagedBean annotation Names can be specified with the name attribute
@ManagedBean(name=someName)
If a name is not specified the class name is used as the Bean name, mixed case starting with lower case The eager attribute can be used to insure that a bean is loaded in a non-lazy fashion
@ManagedBean(name=someName, eager=true)
www.icefaces.org
Session
Lifespan of the HttpSession, destroyed by session timeout or manual invalidation Unique to each user but share across multiple browser tabs
Request
Lifespan duration of an HTTP request received by the server and response sent to client
No Scope
Bean isnt placed into scope
Application Session
www.icefaces.org
Flash
Short conversation-style scope that exists for a single view transition including reloads
Custom
Allows developers to implement their own custom scope behavior
www.icefaces.org
Bean Scopes Once a Bean is defined in the faces-config.xml or via an Annotation it has a default of request scope Bean scope can be defined explicitly in the faces-config.xml
<managed-bean> <managed-bean-name> myBeanName </managed-bean-name> <managed-bean-class> org.mycompany.package.ClassName </managed-bean-class> <mangaged-bean-scope> application|session|view|request|flash </managed-bean-scope> </managed-bean>
www.icefaces.org
www.icefaces.org
www.icefaces.org
Bean Lifecycle JSF implementations running in a Java EE 5 compliant container have access to two other annotations:
@PostConstruct @PreDestroy
www.icefaces.org
Bean Lifecycle When the bean is initialized the method binding for @PostConstruct is called immediately after the Class is initialized
Convenient method for initialization data at construction time @PreDestroy is called just before the Bean is removed from the container management
Bean scope plays an important role as to when this method is called Can be handy for proactively cleaning up a memory foot print or un-registering a class from a listener
www.icefaces.org
End Presentation
www.icefaces.org