OCPSoft.com - Simple SolutionsCommunity Documentation
PrettyFaces provides several methods of generating HTML links via a set of components, and when operating in a JSF 2.0 environment, standard JSF 'h:link' components may be used instead. If the provided mappingId requires any url-pattern-parameters or managed-query-parameters, they can be passed in via the <f:param> tag.
URL pattern parameters can be passed individually, as a java.util.List, or as an
Array. In the latter two cases, toString() will be called on each of the objects in the
list/array. If an empty or null list/array is passed, it will be ignored.
URL path-parameters do NOT have a name attribute, and are parsed in the order they are passed into the tag. Managed query-parameters DO have a name attribute, and order is irrelevant.
PrettyFaces provides a JSF component to output an HTML link to the page. The link tag requires a mapping-id (specified in the pretty-config.xml,) identifying which link to render.
Example 8.1. Using the link component
<url-mapping id="viewItem">
<pattern value="/store/#{ cat : bean.category }/#{ iid : bean.itemId }/" />
<view-id>/faces/shop/item.jsf</view-id>
<action>#{bean.loadItem}</action>
</url-mapping><%@ taglib prefix="pretty" uri="http://ocpsoft.com/prettyfaces" %>
<pretty:link mappingId="viewItem">
<f:param value="#{item.category}" />
<f:param value="#{item.id}" />
View Item. (This is Link Text)
</pretty:link>
Output, assuming that #{item.category} == shoes, and #{item.id} == 24
/store/shoes/24
PrettyFaces provides a JSF component to generate a URL for use as a page scoped variable through El. This tag requires a mapping-id (specified in the pretty-config.xml)
Example 8.2. Using the URL buffer component
<url-mapping id="viewItem">
<pattern value="/store/#{ cat : bean.category }/#{ iid : bean.itemId }/" />
<query-param name="language"> #{ bean.language } </query-param>
<view-id>/faces/shop/item.jsf</view-id>
<action>#{bean.loadItem}</action>
</url-mapping><%@ taglib prefix="pretty" uri="http://ocpsoft.com/prettyfaces" %>
<pretty:urlbuffer var="itemListURL" mappingId="viewItem">
<f:param value="shoes" />
<f:param value="24" />
<f:param name="language" value="en_US" />
</pretty:urlbuffer>
<h:outputText value="Generated URL Is: #{requestScope.itemListURL}" />
Output:
/store/shoes/24?language=en_US
Mappings using DynaView functionality will not function with JSF link components.
Because PrettyFaces provides out-bound URL-rewriting,
one can actually use standard JSF components such as <h:outputLink>
in JSF 1.x, or <h:link> in JSF 2.x.
Example 8.3. Using the <h:outputLink> in JSF 1.x
<url-mapping id="viewItem">
<pattern value="/store/#{ cat : bean.category }/#{ iid : bean.itemId }/" />
<query-param name="language"> #{ bean.language } </query-param>
<view-id>/faces/shop/item.jsf</view-id>
<action>#{bean.loadItem}</action>
</url-mapping><%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <h:outputLink value="/faces/shop/item.jsf"> <f:param name="cat" value="shoes" /> <f:param name="iid" value="24" /> <f:param name="language" value="en_US" /> </h:outputLink>
Output:
/store/shoes/24?language=en_US
In JSF 2.x, you can achieve an even greater level of abstraction by using the mapping-ID
in combination with <h:link>
Example 8.4. Using the <h:link> in JSF 2.x
<url-mapping id="viewItem">
<pattern value="/store/#{ cat : bean.category }/#{ iid : bean.itemId }/" />
<query-param name="language"> #{ bean.language } </query-param>
<view-id>/faces/shop/item.jsf</view-id>
<action>#{bean.loadItem}</action>
</url-mapping>Both of the following components will generate the same output:
<h:link outcome="/faces/shop/item.jsf"> <f:param name="cat" value="shoes" /> <f:param name="iid" value="24" /> <f:param name="language" value="en_US" /> </h:link> <h:link outcome="pretty:viewItem"> <f:param name="cat" value="shoes" /> <f:param name="iid" value="24" /> <f:param name="language" value="en_US" /> </h:link>
Output:
/store/shoes/24?language=en_US