title: Using path parameters in <view-id> with PrettyFaces
body: <p>Many pages in a typical JSF applications are <em>dynamic</em>, meaning that there is a <em>template</em> 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 <code>product.xhtml</code>, and one view parameter, holding the unique field of a product, say <code>name</code>.</p>
  
  <p>With a simple setting we get all requests like <code>/product.xhtml?name=exact-product-name</code> rewritten as, for example, <code>/products/exact-product-name</code>:</p>
  
  <p>The URL mapping:</p>
  
  <pre><code>&lt;url-mapping id="viewProduct"&gt;
      &lt;pattern value="/products/#{ name : productBean.name }" /&gt;
      &lt;view-id value="/store/product.xhtml" /&gt;
      &lt;action&gt; #{ productBean.loadData } &lt;/action&gt;
  &lt;/url-mapping&gt;
  </code></pre>
  
  <p>The view:</p>
  
  <pre><code>&lt;f:metadata&gt;
      &lt;f:viewParam id="name" name="name" required="true" /&gt;
  &lt;/f:metadata&gt;
  </code></pre>
  
  <p>The model:</p>
  
  <pre><code>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";
      }
  
  }
  </code></pre>
  
  <p>However, there are also many pages with <em>static</em> data, that are not <em>templated</em> 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 <code>/pages/articles/article1.xhtml</code> and so on). Using PrettyFaces we would need to create as many URL mapping as the number of such pages. But, <em>in fact</em> this behavior can also be <em>templated</em> in one URL mapping. Unfortunately, this is not supported in current PrettyFaces release.</p>
  
  <p>The proposed enhancement of the PrettyFaces framework is the following:</p>
  
  <pre><code>&lt;url-mapping id="viewArticle"&gt;
      &lt;pattern value="/articles/#{ articleName }" /&gt;
      &lt;view-id value="/store/#{ articleName }.xhtml" /&gt;
  &lt;/url-mapping&gt;
  </code></pre>
  
  <p>or, using an <code>ArticleBean</code> (containing, for example, two fields: <code>articleName</code> and <code>articleId</code>, where name is defined in setter of id field as a unique value):</p>
  
  <pre><code>&lt;url-mapping id="viewArticle"&gt;
      &lt;pattern value="/articles/#{ articleId : articleBean.articleId }" /&gt;
      &lt;view-id value="/store/#{ articleBean.articleName }.xhtml" /&gt;
  &lt;/url-mapping&gt;
  </code></pre>
  
  <p>or using other predefined dependence based on an EL-expression, which is in turn based on a unique correspondence.</p>
  
  <p>I want to emphasize that this is not going to be a <code>DynaView</code> because there is no uncertainty in the view-id: there is a one-to-one correspondence between a <code>&lt;pattern&gt;</code> and a <code>&lt;view-id&gt;</code>.</p>
  
  <p>What do you think about implementing this feature in PrettyFaces?</p>