Java & J2EE Page 3 - Introduction to JavaServer Faces, Part 1 |
You can easily configure a JSF application via an application configuration file. In this file, you can register JavaBeans used in the application, define the program-control flow by specifying page-navigation rules, register custom components, and perform other configuration tasks.
There are a number of aspects of a JSF application that can be configured in the application configuration file. Here, we will focus on how to register JavaBeans (as used in the examples later in this chapter). The application configuration file is explained in detail in Chapter 15. This tells the Web container to load the JavaBean class and create an instance of it when the JSP page is called. The jsp:useBean action needs to be declared in only one page, and it will be usable in all the JSP pages in the same application. A JSF application allows you to do this instead of registering a JavaBean in the application configuration file. However, there is a drawback when using <jsp:useBean> For each JavaBean you want to register in the application configuration file, you use the managed-bean tag inside the faces-config element. Inside the managed-bean element, you have the following subelements:
Here is an example of a managed-bean element:
The managed-bean element in this example is of type myPackage.MyBean and can be referred to as MyBean from any JSP page in the JSF application. The scope of the bean is session, meaning that an instance of this bean is created at the beginning of a user session. The managed-bean element will be explained further in Chapter 3. Later in this chapter, in the “Creating the Page Navigation Example” section, you will see how to use an application configuration file to define page-navigation rules in a JSF application with many pages.
blog comments powered by Disqus |