Java Reference
In-Depth Information
Facelets Enhancements
There have been a handful of updates to the Facelets implementation for JSF 2.2. Improvements and updates include
the following:
The ability to omit XML taglib files for custom components
Facelets resource resolver annotation
This section covers each of these updates briefly and includes examples of each.
Exclude XML from Custom Components
The creation of custom components just got easier with the JSF 2.2 release. In previous versions, Facelets required the
creation of a *-taglib.xml file that contained the name for the component. Once again, we have been mixing XML
configurations into Java applications, making management more tedious. With the release of JSF 2.2, it is now possible
to get rid of the taglib XML and use the @FacesComponent annotation instead, specifying the createTag attribute.
The @FacesComponent annotation should be placed on the custom component class. Table 2-4 lists possible
attributes. To omit the taglib XML, the createTag attribute must be set to true .
Table 2-4. @FacesComponent Attributes
Attribute
Description
createTag
Set to true to make component directly usable via a tag on a Facelet.
tagName
Optional tag name.
namespace
Optional explicit namespace for tag. If omitted, the namespace of
http://xmlns.jcp.org/jsf/component will be used.
value
Custom-component fully qualified name.
An example custom component class is as follows:
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
@FacesComponent(value="components.SpecialComponent", createTag=true,
namespace=" http://www.apress.com/jsf/components " )
public class SpecialComponent extends UIComponentBase {
@Override
public String getFamily() {
// Do something here throw new UnsupportedOperationException("Not supported yet.");
//To change body of generated methods, choose Tools | Templates.
}
//...
}
 
 
Search WWH ::




Custom Search