O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managed Beans

As we’ve just seen, the JSF configuration file has two main sections—one for navigation rules and one for bean definitions. The JSF framework relies on managed beans to glue the user interface (defined primarily in JSP using the JSF tag libraries) to the business logic of your application (which can be whatever sort of code you want).

Managed beans are simply regular Java beans, configured within the faces-config.xml file. The bean class follows the standard JavaBeans rules—a zero-parameter constructor and a set of get/set methods for manipulating properties. In JSF, managed beans also contain action methods . Action methods are invoked by the JSF framework in response to a user action or an event and contain the code that actually manipulates the data model behind your application. In Struts, these methods would correspond to the Action classes that drive the application.

A JSF application usually has two types of managed beans—model beans and backing beans . The difference between the two is more architectural than technical. Model beans focus on integration with the data model of the application. In the Library application, we have model beans (in the com.oreilly.jent.jsf.library.model package) for tasks like managing the book collection itself and for keeping track of user accounts and privileges. Backing beans are linked more directly to the structure of the user interface. A backing bean contains action methods that manipulate the model beans on behalf ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required