Url-rewrite with empty parameters in the Url

Splash Forums PrettyFaces Users Url-rewrite with empty parameters in the Url

Tagged: ,

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

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #18053

    diegomendez29
    Participant

    Hello,

    I have been trying to find the way to create a url patern that matches with empty parameters, but I couldn’t.

    This is the Url-mapping:

    <url-mapping>

    <pattern

    value=”/find/#{a : BackBean.a}/#{b : BackBean.b}/#{c : BackBean.c}/#{d : BackBean.d}/” />

    <view-id value=”/products/find.jspx” />

    </url-mapping>

    But when I hit to the url http://www.mydomain.com/find///// I obtain a 404 page.

    When I hit the http://www.mydomain.com/find/a/b/c/d/ I obtain the find page.

    Thanks in advance.

    #21543

    You need to use a custom regular expression for your parameters:

    <url-mapping>
    <pattern
    value="/find/#{/[^/]*/ a : BackBean.a}/#{/[^/]*/ b : BackBean.b}/#{/[^/]*/ c : BackBean.c}/#{/[^/]*/ d : BackBean.d}/" />
    <view-id value="/products/find.jspx" />
    </url-mapping>

    #21544

    By default parameters match [^/]+, this means that they must have a value. By specifying [^/]*, we tell the regular expression that we don’t care if there is a parameter or not, but it still cannot match a ‘/’

    #21545

    Please let us know know if it works for you. I tried to use custom regular expressions for path parameters in one of my apps yesterday and it didn’t work for some reason. But I didn’t have time to look into this in detail.

    #21546

    diegomendez29
    Participant

    Hello I made a test with the regex that you suggested, and works fine, but It still have an error with the final parameter.

    If I put http://www.mydomain.com/find////d/ it works fine, but when I try with http://www.mydomain.com/find///// I get a 404 page.

    On the other hand, I find another regex that works, it is /.*?/, but It has the same problem with the last parameter.

    Regards,

    #21547

    Hmmm! Could you post the mapping so I can have a look at it?

    #21548

    Or is it exactly the one Lincoln suggested?

    #21549

    diegomendez29
    Participant

    It’s exactly that one.

    <url-mapping>

    <pattern

    value=”/find/#{/[^/]*/ a : BackBean.a}/#{/[^/]*/ b : BackBean.b}/#{/[^/]*/ c : BackBean.c}/#{/[^/]*/ d : BackBean.d}/” />

    <view-id value=”/products/find.jspx” />

    </url-mapping>

    #21550

    Hmm! You are right! This doesn’t work! I’ll try to setup a test case so we can have a look! Thanks for reporting this!

    #21551

    I reproduce this issue. I’ll try to find some time in the next days to fix this.

    In the meantime you can use a simple workaround for the issue. Just append some string to the end of your pattern (after the last / character). I think it will work fine then. Something like this:

    <url-mapping>
    <pattern value="/find/#{/[^/]*/ a : BackBean.a}/#{/[^/]*/ b : BackBean.b}/#{/[^/]*/ c : BackBean.c}/#{/[^/]*/ d : BackBean.d}/result" />
    <view-id value="/products/find.jspx" />
    </url-mapping>

    I hope this helps

    Christian

    #21552
Viewing 11 posts - 1 through 11 (of 11 total)

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

Comments are closed.