Conflict between URL pattern

Splash Forums PrettyFaces Users Conflict between URL pattern

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17800

    lucasmurata
    Participant

    Hello everybody. I am from Brazil and I am big fan of PrettyFaces.

    Sorry for my bad english.

    I have two URL-Mapping – for exemple:

    <url-mapping id=”prehome”>

    <pattern value=”/prehome/” />

    <view-id>/faces/pages/prehome.xhtml</view-id>

    </url-mapping>

    And:

    <url-mapping id=”setor”>

    <pattern value=”/#{a:someBean}/” />

    <view-id>/faces/pages/somepage.xhtml</view-id>

    </url-mapping>

    Secoud mapping is work fine. If I type http://www.page.com/value/ it’s work and the value is setting in my Bean.

    But, when I type http://www.page.com/prehome/ which is mapped in first exemple, this url directs to secound mapping and try to set “prehome” to Bean property.

    How to do for http://www.page.com/prehome/ directs to <pattern value=”/prehome/” />

    <view-id>/faces/pages/prehome.xhtml</view-id> and not to <pattern value=”/#{a:someBean}/” /> ?

    ps.

    Sorry for my English, I tried and i hope you understands :)

    Thanks!

    #20297

    You could try to add a regular expression to your second mapping that prevents that /prehome/ get matched by the second mapping:

    http://ocpsoft.com/docs/prettyfaces/3.1.0/en-US/html_single/#config.pathparams.regex

    http://stackoverflow.com/questions/1061651

    You could also try to change the order of the two mappings in pretty-config.xml. I had a quick look at the code and it seems like the first mapping matching the URL wins! :-)

    #20298

    lucasmurata
    Participant

    Hi chkal,

    Thank you for reply.

    I solved the problem using regex in my secound mapping like you said.

    I include regex [^prehome]. But it is temporary solution.

    Thanks.

    #20299

    Actually Chkal is correct.

    Using regexes is one of the recommended solutions — using regular expression discriminators is an intended use-case.

    The other is simply to put the more-selective url-mappings first, since they are processed in order from top to bottom in the config, which is also a recommended solution.

    Favor ordering before using regexes.

    #20300

    lucasmurata
    Participant

    Hello again,

    Like i said prehome URL problem was solved using [^prehome] in:

    <pattern value=”/[^prehome]#{a:someBean}/” />

    I had not noticed before. When i try access by:

    http://www.page.com/word/

    It’s get the http://www.page.com/%5B^prehome]word/

    How to solve this?

    #20301

    I think your pattern is wrong. It should be something like (I didn’t test it):

    <pattern value="/#{ /(?<=prehome)/ bean.property }/" />

    Take a look at the corresponding chapter of the PrettyFaces documentation how to add custom regex patterns to the URL.

    http://ocpsoft.com/docs/prettyfaces/3.1.0/en-US/html/Configuration.html#config.pathparams.regex

    However I would strongly advise you to try playing with the order of the mappings in your pretty-config.xml instead of using such patterns. I think the patterns are evaluated in the order in which they appear in the file. So if you place your prehome pattern in front of all others it should work like expected.

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

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

Comments are closed.