Beginner needs help with basic prettyfaces concepts

Splash Forums PrettyFaces Users Beginner needs help with basic prettyfaces concepts

This topic contains 7 replies, has 3 voices, and was last updated by  Christian Kaltepoth 11 years, 1 month ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #17819



    I have a bean that has the following URLMapping (bean for home page):

    “@URLMapping(id = “rootAction”, pattern = “/lang/#{accueilView.language}/”, viewId = “/accueil.jsf”)”

    I would like for my app to be able to handle the case when the user lands on the home page without having specified the “/lang/fr/” part of the url, i.e. he/she lands on instead of

    How do I configure my URLMapping in order to handle that case?

    Thanks in advance,



    Create a second mapping without the parameter.

    @URLMapping(id = "root", pattern = "/", viewId = "/accueil.jsf")


    There are multiple ways to achieve something like this. One option is to use the Inbound-URL-Rewriting feature of PrettyFaces. Just add a rewrite rule to your pretty-config.xml like this:

    <rewrite match="/" substitute="/lang/fr/" redirect="301"/>

    If you want to have more control what language to set for the redirect, you could also use a regular URL mapping like this one (pseudo code):

    @URLMapping(id = "start", pattern = "/", viewId = "/something.jsf")
    public class StartPage {

    @Inject / @Autowired / something similar
    private AccueilViewBean accueilView;

    public String action() {

    // get the language by looking up the default language
    // for the user or something like that
    String lang = .....;

    // set value to the correct property

    // send redirect to the target page.
    // the language to use for the link will be extracted
    // from the 'accueilView' bean.
    return "pretty:rootAction";



    Unfortunately you will need a “/something.xhtml” file, although it will not be rendered as the URL action will execute a redirect. But this file can be empty. It is required to be able to enter the JSF lifecycle for this request.

    Here are a few links that may be interesting for you:



    To Lincoln,

    I can have only one URLMapping annotation per class. Can’t I?




    To Christian,

    Thanks for your reply. This is an alternative albeit a bit “heavyweight”.

    Otherwise, do you think I could use a regex that would deal with both patterns? Is that realistic?



    You could try to build such an regex, but I personally would prefer a rewrite rule that redirects to a default language. In this case there would be always a correct language set for the view you are rendering and you won’t need to add special “language is null” handling. Just my two cents! :-)

    Regarding two mappings on one class: Unfortunately this is currently not possible due to limitations of Java annotations. But I already thought about adding a @URLMappings annotation for the next version that could be used to encapsulate multiple @URLMapping annotations. Just like JPA’s @JoinColumns annotation:

    In fact the use of this annotation would look like this:

    @URLMapping(id="mapping1", pattern="/pattern1", viewId="/view1.jsf"),
    @URLMapping(id="mapping2", pattern="/pattern2", viewId="/view2.jsf")
    public class MyBean {

    But in this case @URLQueryParam and @URLAction annotations in the class cannot be assigned easily to the “mapping of the class” as there are multiple ones. I’m unsure how to handle this situation. Perhaps the user should be forced to use the mappingId attribute of the annotations to refer to a specific mapping in this case.



    Hello Christian,

    That’s a good idea.

    Just another question for you: I tried to use the parentId attribute and I noticed it has a different behavior to restfaces’s httpparentaction.

    Here is what I want to achieve:

    Do you see my problem? Can you help?




    Hey balteo,

    I just committed the new @URLMappings annotation to the PrettyFaces trunk. Any chance that you could try the snapshots and check if this new annotation fits you needs?

    Thank you


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

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

Comments are closed.