JSF 2.0 Tag Library
|
|
|
Create a composite tag library
The design of JSF 2.0 is influenced by the philosophy of convention over configuration, popularized by Ruby on Rails. To realize composite components, this philosophy is combined with the resource loading feature, described in Ryan Lubke�s blog JSF 2.0 New Feature Preview Series (Part 2.1): Resources.
The namespace short-name that prefixes a composite component tag, ubiteck :, has an entry in the element, that is, xmlns:ubiteck="http://java.sun.com/jsf/composite/ ubiteck ". The content after http://java.sun.com/jsf/composite/ in this case, ubiteck , is the library-name. The library-name and resource-name are used to create a Resource instance.
JSF 2.0 has a method that creates a UIComponent from a Resource. Due to these conventions, any .xhtml file in a resource library can be accessed as a composite component.
There are several ways to create a resource library. Here is one way to do it.
In your webapp directory, you should have a directory named resources . In this directory is a sub-directory named ubiteck . The name of the subdirectory (in this case, ubiteck ) must correspond to the end part of the composite xmlns for the namespace short-name that prefixes the composite component tag.
| Convention | Value |
|---|---|
| Namespace for composite |
A Composite namespace should start with
http://java.sun.com/jsf/composite/ <Name�of your library> |
| Property access |
A property defined in the interface section should be accessed using
|
|
Structure content under
|
localePrefix/][libraryName/][libraryVersion/]resourceName[/resourceVersion]
|
|
associate a resource with a particular locale identifiter |
If a developer wishes to
|
The default implementation will look for resources in two locations and in the following order:
- /resources this location represents resources in the webapp itself and if present, must be in the root of the web application
- /META-INF/resources this location represents resources on the classpath
HTML Spacer composite component example
Let's imagine we want to create a spacer component. We will create a file called spacer.xhtml in the folder . ./webapp/resources/ubiteck/
The spacer take support a width parameter to define �the length of the spacer. The default value if omiited is 10 pixels.
The graphic image is tag is more described at Tag Graphic Image �(JSF 2.0)
The component will be reachable defining the namespace for ubiteck and calling <ubiteck:spacer width="100"/> and passing the width parameter
Migrate tag library from 1.x to 2.x
Find below a small table with correponding tags or expressions between JSF 1.x and JSF 2.x
| Tags | JSF 1.x | JSF 2.x |
|---|---|---|
| A property attribute | myParam | cc.attrs.myParam |
|
Any child components or template text within the composite component
|
<ui:insert/> |
<composite:insertChildren/> |
| method param | N/A |
<composite:attribute |
| Bean + method | ||
| JSTL Choose |
<c:choose> <c:when test="<condition>"> .... </c:choose> |
...rendered="<condition>" |
| JSTL If conditional |
<c:if test="<condition>"> |
<f:verbatim rendered="<condition>"> |