h:link rendered as http://bla?com.ocpsoft.mappingId=home

Splash Forums PrettyFaces Users h:link rendered as http://bla?com.ocpsoft.mappingId=home

This topic contains 9 replies, has 3 voices, and was last updated by  Christian Kaltepoth 8 years ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #18073


    Hi all,

    I don’t understand clearly how I should use pretty faces for my navigation (using JSF 2.0, Prettyfaces 3.3.0).

    For instance:


    <url-mapping id="accountUsers">
    <pattern value="/#{mybean.currentEnvironment}/#{mybean.subscriptionCode}/admin/account/userlist.html" />
    <view-id value="/account/userlist.html" />

    When I want to link to this view from any other one, I’ve found 3 ways to do it:

    1. <h:link outcome=”pretty:accountUsers” value=”link” />

    This works fine but the link is rendered as


    instead of


    2. <h:commandLink action=”pretty:accountUsers” value=”link”/>

    This works fine with the correct url but is performing a postback for nothing.

    3. <pretty:link mappingId=”accountUsers”>

    <f:param value=”#{mybean.currentEnvironment}”></f:param>

    <f:param value=”#{mybean.subscriptionCode}”></f:param>



    Working as well but I need to specify the parameters on each link, while this is already specified in the pretty faces mapping. Really boring…

    So, how should I write this link ? What I would like to have is the h:link working fine with the correct url…

    Thanks a lot for your help !


    Hey multanis,

    there are many different ways for navigating when using PrettyFaces. Let me first comment on the three ways you mentioned in you post:

    1. <h:link>

    You are not using the h:link correctly here. You have to add the values of the path parameters with <f:param> tags to the component. Please have a look at the documentation for details:


    2. <h:commandLink>

    You are correct. This way should not be used as it creates a postback and not a standard HTML link.

    3. <pretty:link>

    This is the way I prefer in my applications. But you will have to add the desired values of the path parameters here too (like for <h:link>).

    I think that your mapping is a bit different from other mappings because the path parameters typically keep their “current value” for all links generated on the page, correct? But this is some kind of a special case. Typically users want to specify the values of the path parameters as they are different for each link. Therefore the components don’t read the current values from the path parameters but instead offer a way to set them using <f:param> tags. Take a look at this typical example for a mapping:

    <url-mapping id="viewCategory">
    <pattern value="/store/#{ categoryBean.categoryName }/" />
    <view-id value="/faces/shop/store.jsf" />

    <h:dataTable var="cat" value="#{someBean.categories}">
    <pretty:link mappingId="viewCategory">
    <f:param value="#{ cat.name }" />

    As you see from this typical example it makes absolutely sense to specify the values for the path parameters using <f:param> tags.

    So I guess you will have to add the <f:param> tags and go with 1. or 3. to implement what you want. But you could build a simple composite component to simplify the process of creating the links. This should take only a view minutes.

    I hope this helps! :)




    Hi Christian,

    Thanks a lot for your answer, this is what I was afraid of ;-)

    But you are right, my mapping is a bit different as my parameters are always the same once the user is logged in.

    One thing I don’t really understand is why the behaviour is different using h:commandlink or h:link (or pretty:link) ? For instance, is it impossible to have the pretty:link evaluate the EL expressions if the parameter has not been specified ?

    Anyway, I think I’m gonna create my own component for this as you suggested :-)

    Thanks again !


    It’s different for h:commandButton because you typically don’t directly add the navigation outcome to the action attribute but instead call a method in the backend which then returns the navigation outcome. The backend method then simply sets the desired path parameter values directly in the referenced been and returns the PrettyFaces navigation string. This is the only possible way for an action method to “set path parameters”. Actually it is some kind of workaround, because you cannot use something like f:param to build the URL in the action method.

    See the relevant chapter in the documentation for details:


    And yes, you will always have to specify all path parameters of the mapping when using the pretty:link component. Making them optional won’t work because which f:param belongs to which path parameter is determined by looking at the position of the f:param.

    But I think using a simple composite component will help you to create URLs more easily.




    Ok thanks a lot for your lights !



    Christian, that was a very helpful summary, thank you!

    I have a similar situation and this concise explanation puts everything in its place.


    You’re welcome! :)



    JSF 2.1, Primefaces 4.O, Prettyfaces 3.3.3, Omnyfaces 1.6.3, JBoss 7.3
    This is still confusing. Although it might be a result of using too many frameworks in one application.

    <url-mapping id="parent">
            <pattern value="/#{tnt: manager.name}/parent"/>
            <view-id value="/default.jsf"/>
     <url-mapping parentId="parent" id="editPortal">
            <pattern value="/editPortal/#{portalId: portalMaintenance.portalId}"/>
            <view-id value="/parent/portal/edit.jsf"/>


    <h:link value="Link Edit" outcome="pretty:editPortal" styleClass="action-button primary">
       <f:param value="#{manager.name}"/>
       <f:param value="#{portalMaintenance.portalId}"/>


    <h:button outcome="pretty:editPortal" value="Button Edit" styleClass="action-button primary">
        <f:param value="#{manager.name}"/>
        <f:param value="#{portalMaintenance.portalId}"/>

    both results in
    while expected is http://localhost:8080/Test/parent/editPortal/100

    Cannot figure out what is going on here. pretty:urlbuffer and pretty:link work fine.



    Please disregard my previous message.
    I mechanically copied <f:param> without adding “name” attribute (since Pretty Faces link does not require them).


    Nice to hear that you fixed your problem. πŸ™‚

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

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

Comments are closed.