The Java EE 6 Tutorial, Volume I

Using View Parameters

The core tags metadata and f:viewparam, are used as a source of parameters for configuring the URLs. View parameters are declared as part of metadata for a page as shown in the following example:

<h:body>
<f:metadata>
<f:viewParam id="name" name="Name" value="#{sampleBean.username}"/>
<f:viewParam id="ID"  name="uid" value="#{sampleBean.useridentity}"/>

</f:metadata>
<h:link outcome="response" value="Message" includeViewParams="true">
 </h:link>
</h:body>

View parameters are declared with f:viewparam tag and are placed inside the f:metadata tag. If includeViewParams attribute is set on the component, the view parameters are added to the hyperlink.

The resulting URL will look like this:


http://localhost:8080/guessNumber/guess/response.xhtml?Name=Duke&;uid=2001

As the URL can be the result of various parameter values, the order of the URL creation has been predefined. The order in which the various parameter values are read is as under:

  1. Component

  2. Navigation-case parameters

  3. View parameters

When there is a GET request for the page, the Restore View and Render Response phases (sub phases of JavaServer Applications request lifecycle) are executed immediately. In case the page is using view parameters for creating a bookmarkable URL, the post-back request lifecycle is executed with all phases being processed.