JSR-344
JavaServer Faces (JSF) is a user interface (UI) framework for the development of Java web applications. Its primary function is to provide a component-based toolset for easily displaying dynamic data to the user. It also integrates a rich set of patterns to help manage state and promote code reuse.
JSF 2.2 is activated automatically when any JSF *.xhtml file (referred to as a view) is detected in either the web-root directory, or the WEB-INF/resources/ directory. View files may be placed in subdirectories.
Example /catalog/item.xhtml page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:metadata>
<f:viewParam id="id" name="item" value="#{catalog.itemId}"/>
<f:viewAction action="#{catalog.loadItem}"/>
</f:metadata>
<h:head>
<title>Catalog Index</title>
</h:head>
<h:body>
You requested catalog item: <h:outputText value="#{catalog.item.name}"/>
</h:body>
</html>
The above page requires additional functionality for the Expression Language (EL) references, such as viewParam value=”#{catalog.itemId}”, viewAction action=”#{catalog.loadItem}”, and outputText value=”#{catalog.item}”. Below is an example of a CDI managed bean (referred to as a backing bean) that provides the required functionality for the view:
@Named("catalog")
@RequestScoped
public class CatalogViewPage {
private int id;
private Item item;
public String loadItem() {
item = // load the item (which contains a "name" field).
return null;
}
// Getters and setters...
}
JSF 2.2 introduces Faces Flows, which provide an encapsulation of related pages and corresponding backing beans as a module. This module has well-defined entry and exit points defined by the application developer. Each flow resides in its own folder within the web-root directory, and contains a *-flow.xml file. Flow XML files may be empty if no configuration is required.
Example flow layout:
src/main/webapp/
catalog/
item.xhtml
purchase/
purchase-flow.xml
1-cart.xhtml
2-checkout.xhtml
3-confirm.xhtml
The newly introduced CDI @FlowScoped annotation defines the scope of a bean in the specified flow. This enables automatic activation/passivation of the bean when the scope is entered/exited:
@FlowScoped("flow1")
public class MyFlow1Bean {
String address;
String creditCard;
//. . .
}
A new EL object for flow storage, #{flowScope}, is also introduced.
<h:inputText id=“input” value=“#{flowScope.value}” />
Flows may also be defined as CDI classes with producer methods annotated with @FlowDefinition:
class CheckoutFlow implements Serializable {
@Produces
@FlowDefinition
public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {
...
}
}
JSF 2.2 defines Resource Library Contracts, a library of templates and associated resources that can be applied to an entire application in a reusable and interchangeable manner. A configurable set of views in the application will be able to declare themselves as template-clients of any template in the resource library contract.
JSF 2.2 introduces passthrough attributes, which allow listing of arbitrary name/value pairs in a component that are passed straight through to the user agent without interpretation by the UIComponent or Renderer.
Example passthrough attribute:
<html ... xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
<h:form prependId="false">
<h:inputText id="itemId" p:type="number" value="#{catalog.id}"
p:min="1" p:max="1000000" p:required="required"
p:title="Enter an Item ID">
...
This will cause the following output HTML to be generated:
<input id=“itemId” type=“number” value=“1” min=“1” max=“1000000”
required=“required” title=“Enter an Item ID”>
Public API from javax.faces.*:
@FlowScoped |
CDI scope that associates the bean to be in the scope of the specified Flow. |
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}