HTML and CSS Reference
In-Depth Information
<f:viewParam name="number" value="#{car.number}"
required="true"
requiredMessage="You need to specify car number">
<f:validateLongRange minimum="1" maximum="9999999999"/>
</f:viewParam>
</f:metadata>
<h:head>
<title>Car Information</title>
</h:head>
<h:body>
<p>
<h:outputText value="Car Model: #{car.model}" rendered="#{car.model ne null}" /> <br/>
<h:outputText value="Car Color: #{car.color}" rendered="#{car.color ne null}"/> <br/>
<h:outputText value="Car Number: #{car.number}" rendered="#{car.number ne null}"/>
</p>
<h:messages styleClass="errorMessage"/>
</h:body>
</html>
Validation errors will be displayed in
<h:messages/>
; this can happen when for example the URL does not specify
model and color and number parameters or when the number parameter represents an invalid number or out of
range number (the assumed range is from 1 to 9999999999).
In order to support browser bookmarkability and search engine web crawlers, JSF 2.0 (and later) provides
<h:link>
component. If you set
includeViewParams
attribute of
<h:link>
component to
true
, this will generate the
page view parameters as part of the generated URL of the
<h:link>
component. For example, if we added <h:link>
component to the
car.xhtml
page in Listing 4-30 as follows:
<h:link includeViewParams="true" value="Can be bookmarked"/>
This will generate a URL on the following pattern:
<a href="/contextPath/car.xhtml?model=xxx&color=yyy&number=zzz">Can be bookmarked</a>
■
Like
<h:link>
component,
<h:button>
component has
includeViewParams
attribute; however, <h:button>
generates an htML button that depends on JavaScript
onclick
action in order to view target page, which means that it
cannot be reached by web search crawlers.
Note
Adding to
<h:link>
and
<h:button>
, it is also possible to use
includeViewParams
parameter inside the JSF action
attribute (as part of the JSF action outcome), Listing 4-31 shows a JSF input form in a new page (
intro.xhtml
) that
allows the user to enter the car information, as displayed in Listing 4-30.
