Pre-Requisites
  1. J2SE 1.4 or higher (Depending on the version used)
  2. Servlet 2.x
  3. JSP 2.x
Refer your web-server documentation for the JSP and Servlet API version information.
Libraries
The Sun JSF implementation comes with two libraries one for API and other for Implementation. Just drop the libraries into the WEB-INF\lib folder of your web application.
Configuration Files
Create the faces-config.xml configuration file and configure it in the web.xml file. Below is the sample configuration of web.xml to plugin the JSF implementation.
 
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
 
Create properties files
Create the properties files and define the locale based messages. You can use the messages defined in the properties files directly in the JSF pages with simple declaration in the faces-config.xml file. Below is the sample declaration of the properties file.
<application>
<resource-bundle>
<base-name>com.yourcompany.app.resources.messages</base-name>  
<var>msg</var> 
</resource-bundle>
</application>

Create JSF Pages
Write the jsp pages which will present the results of the web application. Use the tag libraries provided by the JSF implementation to design rich UI. Use the expression language of JSF (EL) to put the power of JSF into your application.
Below is the way of including the tag libraries in to your JSP page.
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

Create Managed-Beans
Managed Beans, also called as backing-beans, are standard Java POJO bean whose methods and properties are available to the JSF pages using the JSF Unified Expression Language(EL). Using managed beans, which are generally used as controllers in JSF, you can easily manage the communication between client and server. All the public methods and properties (using standard getter and setter methods) can be accessible using the EL in JSF pages.
Define the managed beans that are required for the controller logic of your application. And configure the beans in the faces-config.xml file. Below is the sample configuration of the managed beans.
<managed-bean>
<managed-bean-name>BeanName</managed-bean-name>
<managed-bean-class>com.yourcompany.yourapp.beanpackage.BeanName</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Define Navigation Rules
Navigation rules tells the container to choose the specified page. The controller, i.e. the backing bean will return the name of the navigation rule which specifies the page to be rendered. This can be achieved by making the managed bean operation return the string containing the name of the navigation rule and the navigation rule with that name is defined in the faces-config.xml file. Here is the sample configuration.
 
<navigation-rule>
<navigation-case>
<from-outcome>NavigationRuleName</from-outcome>
<to-view-id>/path/pageName.jsf</to-view-id>
</navigation-case>
</navigation-rule>
 

Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.

Comments (0)

There are no comments posted here yet