how to use pretty:

Splash Forums PrettyFaces Users how to use pretty:

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #17779



    I’m finding the documentation a little confusing when trying to read what the “pretty:” does when returned from an action.

    I’ve got a very straightforward scenario, I want to navigate to a page that is governed by a pretty faces url, so the actual url is page/1.jsf and I want this to be page/dresses.jsf. I just want to be able to do something like pretty:page/dresses.jsf.

    The documentation seems to suggest I have to write a whole new rule and then reference the mapping id. Then create a bean that will populate the mapping which will then be resent.

    There must be an easier way to do this surely? I’ve also tried it this way and although the pattern gets called it doesn’t work when populated from a bean, it doesn’t inject the value it just resends the url with no value at all. I’ve put a breakpoint to make sure the bean is returning the value as expected which it is but the url is never updated. A static pattern however does work as expected.



    I’ve got the pattern

    “/testing/#{ pageUrl : prettyfacesNavigation.pageUrl }”

    and when it gets put into the browser it doesn’t replace the #{ pageUrl : prettyfacesNavigation.pageUrl } with the value, it just places the pattern into the url.


    The prefix pretty: is always used together with a mapping id. So if you want to use it, you will have to define an URL mapping (in pretty-config.xml or with annotations).

    See the following mapping. I hope this description fits your example:

    <url-mapping id="dressesId">
    <pattern value="/page/dresses.jsf" />

    So when your action returns pretty:dressesId, the user will be redirected to /page/dresses.jsf. This URL will then render the view that is named /page/1.jsf in your application directory (strictly speaking it is /page/1.xhtml).

    If your pattern contains path parameters, PrettyFaces will replace the pattern in the URL by the actual value of the referenced bean property. This means that the bean property must be set to the correct value before returning pretty:dressesId.

    If you want to render links directly in your JSF page, you can use the <pretty:link> component. This way you can directly set the values to be set in the URL pattern. See the documentation for details:



    Hi Chkal,

    Thank you for your explanation, I found this 100% clearer than the documentation. The first part I can get to work no problem, but my problem is more complex. I’m trying to map.

    <url-mapping id=”dressesId”>

    <pattern value=”/#{ pageUrl : prettyfacesNavigation.pageUrl }” />

    <view-id>#{ pageDispatcher.viewOrEdit }</view-id>


    This will allow my pageDispatcher to read the pattern and decide which view to return. However there are two large issues, the first is that the #{ pageUrl : prettyfacesNavigation.pageUrl } never gets replaced and is just put into the url bar (even though the getPageUrl method is called.

    Also my problem is that now all urls coming through the filter will get picked up by this rule when I only want it to be used from urls that are being generated from the prettyfacesNavigation. Not to have urls to populate the prettyfacesNavigation.

    I’ve currently found a bit of a hack to get around this by simply doing a redirect from the action method, however I would like to avoid this as it means another round trip and exiting the JSF lifecycle.


    I’m not sure whether I fully understand what you are trying to achieve.

    I think you are using the wrong PrettyFaces feature for your usecase. If I understand you correctly, you want an URL in the browser bar to get replaced by another URL? This is not a usecase for DynaViews. DynaViews are used to dynamically determine the view to render, but this won’t change the URL shown to the user. For your usecase you may look at the URL rewriting features of PrettyFaces. They allow to rewrite the URL shown in browser bar by using redirects:

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

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

Comments are closed.