URL build question

Splash Forums PrettyFaces Users URL build question

This topic contains 2 replies, has 2 voices, and was last updated by  salpantalpmon 5 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18742

    Got a question regarding how PrettyFaces builds urls

    the config:

    <url-mapping id=”lang”>

    <pattern value=”/#{/[A-Z]{2}/ lang: ctx.lang}” />

    <view-id value=”/index.jsf” />

    </url-mapping>

    <url-mapping id=”translate” parentId=”lang” >

    <pattern value=”/translate” />

    <view-id value=”/translate.jsf” />

    </url-mapping>

    ctx is a session scoped bean. ctx.lang == ‘EN’

    I expect that this link

    <h:link value=”Link” outcome=”pretty:translate” />

    would make URL /EN/translate though it produces /translate.jsf?com.ocpsoft.mappingId=translate

    if i add parameter like this:

    <h:link value=”Link” outcome=”pretty:translate” >

    <f:param name=”lang” value=”#{ctx.lang}” />

    </h:link>

    everything is working as expected. Though i don’t really get why #{ctx.lang} does not get resolved automatically

    I also tried

    <pretty:link mappingId=”translate”>

    <f:param value=”#{ctx.lang}” />

    Link

    </pretty:link>

    it also requires f:param which looks too verbose to me in this situation

    Am i missing something or bean property cannot be resolved for outbound links?

    Thanx in advance

    #23009

    Yes, that’s right. If you are using h:link or pretty:link, you have to specify the values of all path and query parameters using f:param child elements.

    I understand your confusion, but your example is some kind of special case. In a typical use case the path parameter contains something that identifies the resource you are trying to view. Think of a mapping like this:

    <url-mapping id="userDetails">
    <pattern value="/user/#{userDetailsPage.username}" />
    <view-id value="/user-details.jsf" />
    </url-mapping>

    A typical URL for this mapping would be /user/chkal. If you are building a link to a user details page, you will typically not wan’t to use some “current value” to build the URL, but use some value that is available in your current context. Think of a table that lists users. It would look like this:

    <h:dataTable var="user" value="#{userList.users}" ....>

    ...

    <h:column>
    <pretty:link mappingId="userDetails">
    <f:param value="#{user.username}" />
    Show details
    </pretty:link>
    </h:column>

    ...

    This way you can render a large number of links, each one pointing to a different user. We think that this is the most common use case. In your example adding the f:param each time to your link is some kind of redundant, but unfortunately you have to do this to make the link rendering work.

    I hope this explains it. :)

    Christian

    #23010

    Tank you Christian,

    now it’s clear. Solved the issue by adding f:param.

    My case is really somewhat special, but i think it would be nice if pattern could resolve its placeholders on its own if no parameters passed.

    regards

    Alexey

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

You must be logged in to reply to this topic.

Comments are closed.