h:link not work with url-mapping correctly, please help

Splash Forums PrettyFaces Users h:link not work with url-mapping correctly, please help

This topic contains 1 reply, has 2 voices, and was last updated by  Lincoln Baxter III 6 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #17815

    xuzhike
    Participant

    Hi, guys, I use <h:link for Rendering HTML links and URLs with prettyFaces, found it does not work correctly:

    1)

    <url-mapping id=”login”>

    <pattern>/login/#{homeView.text}/</pattern>

    <view-id>/ui/home/login.xhtml</view-id>

    <action>#{homeView.loadCategory}</action>

    </url-mapping>

    in xhtml file:

    the following setting does NOT work:

    1: <h:link outcome=”pretty:login” value=”login1″><f:param value=”login1″ />

    output: http://localhost:8080/jiaChaoshi/ui/home/login.xhtml

    2: <h:link outcome=”/ui/home/login.xhtml” value=”login2″><f:param value=”login2″ />

    output: http://localhost:8080/jiaChaoshi/ui/home/login.xhtml

    3: <h:link outcome=”pretty:login” value=”login3″><f:param name=”cat” value=”shoes” /></h:link>

    <h:link outcome=”/ui/home/login.xhtml” value=”login3″><f:param name=”cat” value=”shoes” /></h:link>

    both output: http://localhost:8080/jiaChaoshi/ui/home/login.xhtml?cat=shoes

    but the setting is correct:

    <pretty:link mappingId=”login”><f:param value=”login_testing” />login</pretty:link>

    output: http://localhost:8080/jiaChaoshi/login/login_testing/


    another pretty-config.xml

    <url-mapping id=”login”>

    <pattern>/login/#{cat:homeView.text}/</pattern>

    <view-id>/ui/home/login.xhtml</view-id>

    <action>#{homeView.loadCategory}</action>

    </url-mapping>

    see the following setting and output:

    1:<h:link outcome=”pretty:login” value=”login3″><f:param name=”cat” value=”shoes” /></h:link>

    <h:link outcome=”/ui/home/login.xhtml” value=”login3″><f:param name=”cat” value=”shoes” /></h:link>

    both output: http://localhost:8080/jiaChaoshi/login/shoes/

    is it right?

    2: <h:link outcome=”pretty:login” value=”login1″><f:param value=”login1″ />

    <h:link outcome=”/ui/home/login.xhtml” value=”login1″><f:param value=”login1″ />

    output: http://localhost:8080/jiaChaoshi/ui/home/login.xhtml

    wrong.

    3: <pretty:link mappingId=”login”><f:param value=”login2″ />login</pretty:link>

    output: http://localhost:8080/jiaChaoshi/login/login2/

    why the first pretty-config.xml not work with <h:link?

    for <pattern>/login/#{cat:homeView.text}/</pattern>, is cat mandatory?

    or am I missing something?

    thx a lot

    #20387

    Hi @xuzhike,

    This is correct behavior. <h:link> is a JSF2 component, and does not function the same way as <pretty:link> in the way that it accepts parameters.

    You must follow the rules set by <h:link> when passing <f:param>.

    <h:link> does not accept un-named parameters, since that’s not how URLs work in JSF2 by default. Using a prettyfaces mappingId in the outcome-"" attribute does not change this.

    In order for <h:link> to function properly, all parameters must have both a name and a value:

    <f:param name="cat" value="myValue">

    PrettyFaces then uses that name to determine which parameter in the path the value belongs; in this case, which is cat:

    <pattern>/login/#{ cat : homeView.text}/</pattern>
    ^

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

You must be logged in to reply to this topic.

Comments are closed.