Book Image

Digital Java EE 7 Web Application Development

By : Peter Pilgrim
Book Image

Digital Java EE 7 Web Application Development

By: Peter Pilgrim

Overview of this book

Digital Java EE 7 presents you with an opportunity to master writing great enterprise web software using the Java EE 7 platform with the modern approach to digital service standards. You will first learn about the lifecycle and phases of JavaServer Faces, become completely proficient with different validation models and schemes, and then find out exactly how to apply AJAX validations and requests. Next, you will touch base with JSF in order to understand how relevant CDI scopes work. Later, you’ll discover how to add finesse and pizzazz to your digital work in order to improve the design of your e-commerce application. Finally, you will deep dive into AngularJS development in order to keep pace with other popular choices, such as Backbone and Ember JS. By the end of this thorough guide, you’ll have polished your skills on the Digital Java EE 7 platform and be able to creat exiting web application.
Table of Contents (21 chapters)
Digital Java EE 7 Web Application Development
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

A Faces servlet


In JSF, FacesServlet acts as the front controller, is the conduit for all the requests, and also sends the response back to the client. This servlet is a subclass of javax.servlet.Servlet.

A web browser client sends an HTTP request to the servlet container. If it is a Faces request, then the servlet container invokes the service() method of FacesServlet. The method hands over the processing of the request to a member instance javax.faces.lifecycle.LifeCycle object. The method also creates a FacesContext instance. The LifeCycle instance is responsible for the processing of a request to all of the JSF phases described in Chapter 2, JavaServer Faces Lifecycle and the rendering of the response.

Reconfiguration of the resource paths

It is possible to change the path name of the resource lookup and contract folders as well by configuring the web XML deployment descriptor. The constants are defined in the javax.faces.application.ResourceHandler class. The WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME string constant defines the resource directory property's name and WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME defines the contract directory property.

We can redefine the JSF web application defaults with the following web.xml settings:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" ...>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <init-param>
      <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
      <param-value>/myresources</param-value>
    </init-param>
    <init-param>
      <param-name>javax.faces.WEBAPP_CONTRACTS_DIRECTORY</param-name>
      <param-value>/mycontracts</param-value>
    </init-param>
  </servlet> ...
</web-app>

We can specify the initial parameters on the Faces servlet in overriding the default configuration.

A JSF-specific configuration

The Faces servlet understands several other configuration parameters. Here is a table of the possible parameter names. These are prefixed with javax.faces:

Parameter name

Description

CONFIG_FILES

This specifies a comma-delimited list of the additional context related resource paths that are loaded automatically with WEB-INF/faces-config.xml.

DEFAULT_SUFFIX

This sets the suffix for the JSF files; the default is *.xhtml. If you change this configuration, then I recommend that you also change welcome-file-list in web.xml.

DISABLE_FACELET_JSF_VIEW_HANDLER

If this parameter is set to true, then it disables Facelets as the default page declaration language. The default is false.

FACELETS_BUFFER_SIZE

This specifies the buffer size for a JSF response. The default size is -1, which means an unlimited size.

FACELETS_REFRESH_PERIOD

This sets the interval time in seconds that the JSF compiler should check for changes. In the production mode, this value is set to -1, which means that the JSF compiler should not check; otherwise, the default is set to 2 in the reference implementation.

FACELETS_SKIP_COMMENT

This is a Boolean value that determines if the XML comments in a Facelets view is included in a response. The default value is true.

FACELETS_LIBRARIES

This specifies a semicolon delimited list collection of the Facelets tag libraries by a path.

LIFECYCLE_ID

This overrides the default implementation of the JSF javax.faces.lifecycle.Lifecycle instance.

PROJECT_STAGE

This specifies the development project stage. The acceptable values are Development, UnitTest, SystemTest, or Production.

STATE_SAVING_METHOD

This specifies the location where a state is saved in a JSF application. The acceptable values are client and server.

WEBAPP_CONTRACTS_DIRECTORY

This overrides the default location of the JSF resource contracts. The default is <web-context>/contracts.

WEBAPP_RESOURCES_DIRECTORY

This overrides the default location of the JSF resources reserved for the digital assets. The default is <web-context>/resources.

These settings are best configured in the web deployment descriptor file (web.xml).