HTML and CSS Reference
In-Depth Information
Passing Through Elements
HTML5 introduces new elements that do not have JSF counterparts such as <section /> and <meter />. To avoid the
need for page authors to revert back to the work-around of writing composite components, an attribute namespace
(
jsf
) was introduced. The jsf namespace contains the attributes normally found on a
UIComponent
. When using the
jsf
namespace, Facelets detects that you want to treat the tag as a
UIComponent
and maps it accordingly. In Listing 5-8
the
<progress>
tag is converted to a
UIComponent
by using the
jsf:id
attribute.
Listing 5-8.
Passing Through Elements Using the jsf Attribute Namespace
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:h="
http://xmlns.jcp.org/jsf/html
"
xmlns:jsf="
http://xmlns.jcp.org/jsf
"
>
<h:body>
<h:form>
<progress jsf:id="progressbar"
value="#{imageGeneration.progress}"
max="100" />
</h:form>
</h:body>
</html>
Technically it is the Facelets
TagDecorator
that is responsible for treating custom elements as
UIComponent
s. In
some situations the
TagDecorator
will recognize the exactly equivalent
UIComponent
of the HTML tag. In Listing 5-9,
the HTML tag and the JSF tag will produce the same output and component tree. This is a great addition to JSF if you
prefer to write your views as close to HTML as possible.
Listing 5-9.
Automatic Mapping Between HTML and JSF Tags
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:h="
http://xmlns.jcp.org/jsf/html
"
xmlns:jsf="
http://xmlns.jcp.org/jsf
"
>
<h:body>
<h:form>
<input type="text" jsf:value="#{registration.firstName}" />
<h:inputText value="#{registration.lastName}" />
</h:form>
</h:body>
</html>
Resource Library Contracts
JSF 2.0 introduced the resource library, where cascading style sheets, javascripts, images, and composite components
resided in the
resources/
directory or were packaged in the
META-INF/resources
directory of a JAR file. Resource
library contracts take this feature a step further by introducing the possibility of having multiple resource libraries.