What is the correct way to use pattern values?

Splash Forums PrettyFaces Users What is the correct way to use pattern values?

This topic contains 6 replies, has 2 voices, and was last updated by  Christian Kaltepoth 6 years, 7 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #27154


    What is the correct way to use pattern values, and REST url’s?

    my goal is to use pattern value for url parameters (REST)and the view-id value for further request handling i.e. session and security.
    This so that I can seperate url (pattern value)logics from my further logics(iew-id value).

    For example:
    pattern value: go to area bean.
    view-id value: Is user logged in bean? If not go to login page.

     <url-mapping id="masterPage">
    <pattern value="/#{pageBean.page}" />
    <view-id value="#{loginBean.getLogin}" />

    The view-id value is now working correctly.

    This topic was already discussed at: http://www.ocpsoft.org/support/topic/dynamic-view-id-not-working/

    My current problem is that the pattern value only works with bean properties.

    <pattern value="/#{pageBean.page}" />

    This wasn’t a good idea according to the following reaction:

    Could you explain a bit more what is not working? Which of the two mappings?
    Please not that pattern such as are not a very good idea, as they match nearly every request. Even things like /style.css…

    But in the OCPsoft prettyfaces manual chapter: 3.2.2. * EL-injected path parameters.
    The example pattern is:

    <pattern value="/store/#{ bean.category }/" />

    with this bean:

    public class CategoryBean {
    private String category;
    /* Getters & Setters */

    Wasn’t this the wrong pattern? Becuase it reacts to things like /style.css…

    So how can I use pattern value’s the right and safe way.

    This doesn’t work

    <pattern value="/#{pageBean.getpage}" />

    And this does.

    <pattern value="/#{pageBean.page}" />

    With this Bean

    package navigation;
     * @author peter
    import java.io.Serializable;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.RequestScoped;
    public class PageBean implements Serializable{
    	private String page;
    	public void setPage(String page){
    	public String getPage(){
        	return "admin";

    The error explains that im not using a bean property.

    Please help me out.
    How can I use pattern values the right way?
    Thanks a lot.


    To be honest. I don’t think that using such a general pattern and using dyna-view for all pages is a very good idea. Especially because dyna-view doesn’t support outbound rewriting.

    If you want to implement redirection to a login page for unauthenticated user, you should simply use a servlet filter or something like that. You could also use Rewrite for such scenarios if you like.

    If you have other requirements beside security, please post them and I can suggest what to do.



    Well I have a JSF application for http handling and a seperated EJB app for Bussiness Logics.
    The JSF application is just a templating system to represent the Bussiness Logics in a browser.
    Depending on the modules I use in the EJB I want to represent this data with the JSF templating.
    I do this with Injection and the abstract facade design pattern.
    So without ever having to configure the JSF app I want to represent this EJB data depending on the modules available.

    Adding shoe store module to EJB (has also the logics for building urls).
    So the JSF Bean moduleBean.geturl() Checks for modules and the module returns the url to the jsf app:


    <pattern value="/#{moduleBean.geturl}" />

    So the view ID seperately checks session with another bean. When ok. the JSF app shows shoe store contents.

    So basically I wanted to use the pattern value for ¨dynamic¨ urls


    • This reply was modified 6 years, 7 months ago by  Peter-TI.

    Hmmm. So your EJBs are also responsible for URL handling?

    I suggest to have a look at Rewrite (which is basically the “core” of PrettyFaces). It allows you to do configuration programmatically which perhaps works better with your module system. With Rewrite you can have multiple “ConfigurationProvider” implementation. Each implementation contributes mapping configuration to Rewrite. That would perhaps be a good fit for your module structure. Especially you could ask your EJB at startup for the mapping metadata and configure Rewrite accordingly.

    I wrote a Prettyfaces3-to-Rewrite Migration guide some time ago. That may be helpful for you to understand how to represent the classic pretty-config.xml configuration with ConfigurationProdivers.




    Indirectly, yes.
    The WAR module checks if an EJB module is available.
    I made the modules swappable depending on project needs.

    The EJB (shoestore) module returns its own url representation as a String for example:


    The EJB shoestore module also returns a selected entity as string:


    (which is a shoe type and color…)

    Now because the WAR recognized the´re is an EJB shoe store module.
    The WAR bean moduelBean.geturl() asks the EJB shoestore the url representation;

    this means I wouldn´t have to change the pretty-config.xml file undispite changing EJB Modules.
    (I just wanted to try something new.)


     <pattern value="/#{moduleBean.geturl}" />

    This pattern value would in this case represent:

    The problem is that in this way this pattern value collects all url extensions and not just stops after: shoestore.
    So what I want to achieve is that my module bean would only return the string of my available modules. After that I just want all other pattern values in pretty-faces.xml to be executed.

    I guess diving into rewrite would be the best idea.
    Any advise?

    Thanks a lot!



    I think I finally found where I was looking for(in the manual 🙂 ):


    and parent ID

    So I could I use it like this, defining store:

    <url-mapping id="viewItem">
      <pattern value="/store/item/#{ iid : bean.itemId }/" />
      <view-id value="/#pageBean.getPage" />
      <query-param name="language"> #{bean.language} </query-param>

    With the property:


    with the beans:

    Setting bean.itemId

    Or can I use pretty faces like this, the parent child way.?Hopefully a solustion for what I intended:
    This examle is with the shoestore module:

    <url-mapping id="module"> 
       <pattern value="/bean.module" /> 
       	<~-- Result: /shoestore -->
       <view-id value="/#{pageBean.getPage}" />
    <url-mapping parentId="module" id="phase1"> 
       <pattern value="/#{phase1}" /> 
       	<~-- Result: /shoestore/#{phase1} -->
       <view-id value="#{pageBean.getPage}" /> 
    <url-mapping parentId="module" id="phase2"> 
       <pattern value="/#{phase2}" /> 
       	<~-- Result: /shoestore/#{phase1}/#{phase2} -->
       <view-id value="#{pageBean.getPage}" /> 

    With property:

    with the beans:

    module name is set as bean.module propertie after some checks
    phase is set after some checks

    Is this possible with <action>?
    So is the pattern value set with the action properly? Do I not have to put the <action> above the pattern value?
    Could I also add query parameters in this parent, child way?
    Is it possible to add the module variable in a commandlink or commandButton, and not to use url-mapping id? This with above parent child example?
    For example:

    <h:commandLink action="pretty:shoestore"> Shoe Store </h:commandLink> 

    I must confess, I don’t fully understand your example.

    You should really have a deeper look at Rewrite. Rewrite is much more flexible when implementing such custom requirements.

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.