Quick Starter Guide To JavaServer Faces (JSF)
J2SE 1.4 or higher (Depending on the version used)
Refer your web-server documentation for the JSP and Servlet API version information.
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.
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.
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" %>
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.
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.
Like it on Facebook, Tweet it or share this article on other bookmarking websites.