Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Configuring managed beans in XML


JSF managed bean configuration was essentially improved starting with JSF 2.0. Most commonly, a managed bean is annotated with @ManagedBean and another annotation indicating a JSF scope (for example, @RequestScoped). But managed beans can be configured in faces-config.xml as well, and this approach is not deprecated or obsolete. The simplest configuration contains the managed bean's name, class, and scope:

<managed-bean>
  <managed-bean-name>playersBean</managed-bean-name>
  <managed-bean-class>book.beans.PlayersBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
...
</managed-bean>

Note

In case that you need a managed bean that should be eagerly initialized, you can use the eager attribute of the <managed-bean> tag:

<managed-bean eager="true">

Managed beans' properties can be initialized from faces-config.xml using the <managed-property> tag as follows:

<managed-property...