Book Image

JSF 2.0 Cookbook

By : Anghel Leonard
Book Image

JSF 2.0 Cookbook

By: Anghel Leonard

Overview of this book

<p>JavaServer Faces is a Java-based Web application framework intended to simplify development of user interfaces for Java EE applications. You may already be aware of the laborious search through reference guides and documentation to develop your JSF applications. With the JSF Cookbook, you can find solutions to the most common JSF problems in a quick and easy way.<br /><br />This book will cover all the important aspects involved in developing JSF applications. It provides clear instructions for getting the most out of JSF and offers many exercises to build impressive desktop-style interfaces for your web applications. Develop JSF applications starting with simple recipes and gradually moving on to complex recipes.<br /><br />We discuss all of the fundamental aspects of JSF applications. Once you locate your desired topic, you can try to find a recipe that corresponds to your problem. <br /><br />We start off with the simple concepts of Converters, validators and file management. We then work our way with various resources such as CSS, JavaScript, and images to improve your web applications. You will learn to build simple and complex custom components to suit your needs. Next, you get to exploit AJAX as well as implement internationalization and localization for your JSF applications. We then look into ensuring security for your applications and perform testing of your applications. You also get to learn all about Facelets and explore the newest JSF 2.0 features. Finally you get learn a few integrations such as JSTL with JSF, Spring with JSF, and Hibernate with JSF. All these concepts are presented in the form of easy-to-follow recipes.<br /><br />Each chapter discusses separate types of recipes and they are presented with an increasing level of complexity from simple to advanced. All of these recipes can be used with JSF 1.2 as well.</p>
Table of Contents (19 chapters)
JSF 2.0 Cookbook
Credits
About the Author
About the Reviewer
Preface
Index

Prime Faces (supports JSF 2.0)


Namespaces: http://primefaces.prime.com.tr/ui (prefix: p)

In any JSF page that uses PrimeFaces, you should place in the <head> section the following tag. This tag loads PrimeFaces resources:

<p:resources />

A JSF web.xml file configured for PrimeFaces look like this (the bolded code is specific to PrimeFaces):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
         http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
  </context-param>
  <context-param>
    <description>
      Parameter required by PrimeFaces 2.0 and Mojarra 2.0
    </description>
    <param-name>com.sun.faces.allowTextChildren</param-name>
    <param-value>true</param-value>
  </context-param>
  <servlet>
    <description>This servlet injects PrimeFaces 2.0</description>
    <servlet-name>Resource Servlet</servlet-name>
    <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Resource Servlet</servlet-name>
    <url-pattern>/primefaces_resource/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>
      30
    </session-timeout>
  </session-config>
  <welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>
  </welcome-file-list>
</web-app>

If you need to use the PrimeFaces upload support, you need to configure the PrimeFaces FileUpload Filter like this (this should be the first filter in web.xml):

<filter>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
  <init-param>
    <param-name>thresholdSize</param-name>
    <param-value>51200</param-value>
  </init-param> 
</filter>
<filter-mapping>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>