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 3 years, 8 months ago.

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

    multanis
    Participant

    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:

    pretty-config.xml:

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

    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

    http://domain/bla/otherpage.html?com.ocpsoft.mappingId=accountUsers&#8221;

    instead of

    http://domain/bla/prod/45-89552-33/admin/account/userlist.html&#8221;

    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>

    link

    </pretty:link>

    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 !

    #21634

    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:

    http://ocpsoft.com/docs/prettyfaces/3.3.0/en-US/html/outbound_rewriting.html#jsf

    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" />
    </url-mapping>

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

    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! :)

    Christian

    #21635

    multanis
    Participant

    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 !

    #21636

    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:

    http://ocpsoft.com/docs/prettyfaces/3.3.0/en-US/html/navigation.html#navigation.actions

    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.

    Christian

    #21637

    multanis
    Participant

    Ok thanks a lot for your lights !

    #21638

    azakovorotny
    Participant

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

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

    #21639

    You’re welcome! :)

    #25763

    azakovorotny
    Participant

    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>
     ...  
     <url-mapping parentId="parent" id="editPortal">
            <pattern value="/editPortal/#{portalId: portalMaintenance.portalId}"/>
            <view-id value="/parent/portal/edit.jsf"/>
            <action>#{portalMaintenance.loadPortal}</action>
        </url-mapping>
    

    Either

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

    or

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

    both results in
    http://localhost:8080/Test/parent/portal/edit?com.ocpsoft.mappingId=editPortal
    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.

    • This reply was modified 3 years, 8 months ago by  azakovorotny.
    • This reply was modified 3 years, 8 months ago by  azakovorotny.
    #25766

    azakovorotny
    Participant

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

    #25767

    Nice to hear that you fixed your problem. 🙂

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

You must be logged in to reply to this topic.

Comments are closed.