Issue : pretty:link trailing '?'

Splash Forums PrettyFaces Users Issue : pretty:link trailing '?'

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

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #18444

    LaChamelle
    Participant

    Hi,

    I’m doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate Provider. The application run on Tomcat 7.27.

    I use PrettyFaces 3.3.3 for url management.

    I notice a small “issue” with the pretty:link : It’s generate an extra ‘?’ at the end of the url in some case:

    For example this pretty:link :

    <pretty:link mappingId="#{prettyManager.currentMappingId}" rendered="#{prettyManager.currentMappingId ne 'emptyhome'}" styleClass="langue">
    <f:param value="#{acceptedLanguage}"/>
    <f:param value="#{prettyManager.urlSiteId}" rendered="#{prettyManager.urlSiteId != null}"/>
    <f:param value="#{prettyManager.urlThemeId}" rendered="#{prettyManager.urlThemeId != null}"/>
    #{acceptedLanguage}
    </pretty:link>

    Generate url like this : http://localhost/Mywebapp/siteCreation/FR/aSiteId?

    Whereas this h:link :

    <h:link outcome="pretty:#{prettyManager.currentMappingId}" rendered="#{prettyManager.currentMappingId ne 'emptyhome'}" styleClass="langue">
    <f:param name="lang" value="#{acceptedLanguage}"/>
    <f:param name="siteId" value="#{prettyManager.urlSiteId}" rendered="#{prettyManager.urlSiteId != null}"/>
    <f:param value="#{prettyManager.urlThemeId}" rendered="#{prettyManager.urlThemeId != null}"/>
    #{acceptedLanguage}
    </h:link>

    Generate url like this : http://localhost/Mywebapp/siteCreation/FR/aSiteId

    Thanks.

    #22622

    Hi,

    thanks for bringing this up. Could you perhaps post one of the patterns for which this happens?

    Thanks

    Christian

    #22623

    LaChamelle
    Participant

    Hi,

    When one f:param is not rendered its generate an extra ‘?’

    <h:link outcome="pretty:#{prettyManager.currentMappingId}" rendered="#{prettyManager.currentMappingId ne 'emptyhome'}" styleClass="langue">
    <f:param name="lang" value="#{acceptedLanguage}"/>
    <f:param name="siteId" value="#{prettyManager.urlSiteId}" rendered="#{prettyManager.urlSiteId != null}"/>
    <f:param value="#{prettyManager.urlThemeId}" rendered="#{prettyManager.urlThemeId != null}"/>
    #{acceptedLanguage}
    </h:link>

    Thanks.

    #22624

    I really think that the trailing ? has something to do with the fact that you are using rendered for <f:param> which is IMHO not valid. And to be honest. I do not fully understand how your mappings look like. It seems like the siteId and urlThemeId are path parameters. And path parameters aren’t allowed to be optional.

    #22625

    I just had a look at the spec. There is no rendered attribute. Just a disabled attribute.

    http://javaserverfaces.java.net/nonav/docs/2.1/vdldocs/facelets/f/param.html

    But I don’t know if disabled would be correctly handled by PrettyFaces.

    #22626

    LaChamelle
    Participant

    The mapping is like this:

    <url-mapping id="themes">
    <pattern value="/themes/#{lang : prettyManager.urlLangId}/#{siteId : prettyManager.urlSiteId}" />
    <view-id value="themes.jsf" />
    <action onPostback="false">#{prettyManager.processThemeList}</action>
    </url-mapping>

    <url-mapping id="themeSettings">
    <pattern value="/themeSettings/#{lang : prettyManager.urlLangId}/#{siteId : prettyManager.urlSiteId}/#{themeId : prettyManager.urlThemeId}" />
    <view-id value="themeSettings.jsf" />
    <action onPostback="false">#{prettyManager.processThemeSettings}</action>
    </url-mapping>

    For the attribute rendered, it’s Netbeans which give me the completion. I have read that all the component inherit from rendered and id attribute.

    #22627

    LaChamelle
    Participant

    Same without the attribute rendered it’s generate an extra ‘?’

    #22628

    Is it possible that the ? is only appended if one of the <f:param> elements has a value of null?

    #22629

    LaChamelle
    Participant

    Yes the ? append when one f:param is null. No matter the rendered, when the param is null.

    #22630

    Thanks for the update.

    As mentioned earlier, path parameters are not allowed to be null. Actually it’s a bug that PrettyFaces doesn’t throw an exception telling you about this. :)

    What I still don’t understand is, what you expect PrettyFaces to do if a path parameter is null. Take this example:

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

    What should an URL look if category is null?

    #22631

    LaChamelle
    Participant

    Most of the time, in my url the two first param are the same, only the third change:

    <url-mapping id="themes">
    <pattern value="/themes/#{lang : prettyManager.urlLangId}/#{siteId : prettyManager.urlSiteId}" />
    <view-id value="themes.jsf" />
    <action onPostback="false">#{prettyManager.processThemeList}</action>
    </url-mapping>

    <url-mapping id="themeSettings">
    <pattern value="/themeSettings/#{lang : prettyManager.urlLangId}/#{siteId : prettyManager.urlSiteId}/#{themeId : prettyManager.urlThemeId}" />
    <view-id value="themeSettings.jsf" />
    <action onPostback="false">#{prettyManager.processThemeSettings}</action>
    </url-mapping>

    But if the urlSiteId is null then PrettyFaces tell it cannot build the link.

    I suppose that the pretty:link component add an ‘?’ cause I give him a extra null parameter, all the required param are defined.

    <pretty:link mappingId="themes" rendered="#{prettyManager.currentMappingId ne 'emptyhome'}" styleClass="langue">
    <f:param value="#{acceptedLanguage}"/>
    <f:param value="#{prettyManager.urlSiteId}" />
    <f:param value="#{prettyManager.aNullValue}" />
    #{acceptedLanguage}
    </pretty:link>

    #22632

    Ah, now I got it. Sorry.

    Actually the mappingId for which you are rendering the URL is dynamic. So the value of an <f:param> gets only null if it isn’t used in the mapping at all. Right? So this explains why PrettyFaces isn’t complaining about path parameters being null.

    So the root cause of the problems is that you have sometimes more <f:param> then required of the mappingId to be rendered.

    I think this cannot be fixed easily in PrettyFaces. The problem is that the <f:param> components must match the parameters of the mapping. But that’s difficult to achieve in your use case.

    One workaround for you would be to have multiple <pretty:link> which get rendered depending on which path parameters are null. Something like this:

    <!-- one path parameter -->
    <h:panelGroup rendered="#{prettyManager.urlSiteId == null and prettyManager.urlThemeId == null}">
    <pretty:link mappingId="#{prettyManager.currentMappingId}" rendered="#{prettyManager.currentMappingId ne 'emptyhome'}" styleClass="langue">
    <f:param value="#{acceptedLanguage}"/>
    #{acceptedLanguage}
    </pretty:link>
    </h:panelGroup>

    <!-- three path parameters -->
    <h:panelGroup rendered="#{prettyManager.urlSiteId != null and prettyManager.urlThemeId != null}">
    <pretty:link mappingId="#{prettyManager.currentMappingId}" rendered="#{prettyManager.currentMappingId ne 'emptyhome'}" styleClass="langue">
    <f:param value="#{acceptedLanguage}"/>
    <f:param value="#{prettyManager.urlSiteId}" />
    <f:param value="#{prettyManager.urlThemeId}" />
    #{acceptedLanguage}
    </pretty:link>
    </h:panelGroup>

    This should work. I know it’s not a nice solution. But this would be correct usage of the pretty:link component.

    #22633

    Ups, concurrent posts. :)

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

You must be logged in to reply to this topic.

Comments are closed.