Many pages in a typical JSF applications are dynamic, meaning that there is a template view that would be used to render every object of a given type. For these pages PrettyFaces rewriting solution works great and effortless. An example is a web application that displays a product, basing on its id, or other unique field. There is typically one view related to such a display, say product.xhtml
, and one view parameter, holding the unique field of a product, say name
.
With a simple setting we get all requests like /product.xhtml?name=exact-product-name
rewritten as, for example, /products/exact-product-name
:
The URL mapping:
<url-mapping id="viewProduct">
<pattern value="/products/#{ name : productBean.name }" />
<view-id value="/store/product.xhtml" />
<action> #{ productBean.loadData } </action>
</url-mapping>
The view:
<f:metadata>
<f:viewParam id="name" name="name" required="true" />
</f:metadata>
The model:
public class ProductBean implements Serializable {
private ProductService productService;
private String name;
private Product product;
public String loadData() {
if(!((name == null) || (name.equals(""))) {
Product product = productService.findByName(name);
this.product = product;
return null;
}
return "error";
}
}
However, there are also many pages with static data, that are not templated in a way described above, using view parameters. These pages simply display what was put in them. For example, there may be many articles that were created as separate views (like /pages/articles/article1.xhtml
and so on). Using PrettyFaces we would need to create as many URL mapping as the number of such pages. But, in fact this behavior can also be templated in one URL mapping. Unfortunately, this is not supported in current PrettyFaces release.
The proposed enhancement of the PrettyFaces framework is the following:
<url-mapping id="viewArticle">
<pattern value="/articles/#{ articleName }" />
<view-id value="/store/#{ articleName }.xhtml" />
</url-mapping>
or, using an ArticleBean
(containing, for example, two fields: articleName
and articleId
, where name is defined in setter of id field as a unique value):
<url-mapping id="viewArticle">
<pattern value="/articles/#{ articleId : articleBean.articleId }" />
<view-id value="/store/#{ articleBean.articleName }.xhtml" />
</url-mapping>
or using other predefined dependence based on an EL-expression, which is in turn based on a unique correspondence.
I want to emphasize that this is not going to be a DynaView
because there is no uncertainty in the view-id: there is a one-to-one correspondence between a <pattern>
and a <view-id>
.
What do you think about implementing this feature in PrettyFaces?