Match anything in pattern using regexp

Splash Forums PrettyFaces Users Match anything in pattern using regexp

This topic contains 4 replies, has 2 voices, and was last updated by  djmj 8 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #24605


    How do I match anything in pattern using regular expression?

    I have following structure:

    <!-- display entity welcome page-->
    	<pattern value="/entity"/>
    	<view-id value="/sites/entity.xhtml"/>
    <!-- display particular entity -->
    	<pattern value="/([^/]+)/#{entityId}"/>
    	<view-id value="/sites/entity.xhtml"/>

    The first part of the path should match anything that is not empty, its value is currently not important:


    I get following strange exception:

    java.util.regex.PatternSyntaxException: Unclosed character class near index 5

    I also tried to match it as an optional parameter with following patterns which resulted in correct redirection and link building but jsf could not load my resources like js/css anymore which broke my page.

    <pattern value="/entity/#{entityId}"/>
    <pattern value="/#{entitySeoId}/#{entityId}"/>

    The idea of allowing random string is much more convenient for my use case which is simliar to product site urls

    • This topic was modified 8 years, 5 months ago by  djmj.
    • This topic was modified 8 years, 5 months ago by  Christian Kaltepoth.
    • This topic was modified 8 years, 5 months ago by  djmj. Reason: last pattern not shown

    There are two things you could try:

    First try to remove ( and ) from the pattern. I don’t see any reason to add them here. So use something like this:

    <pattern value="/[^/]+/#{entityId}"/>

    You should also be able to simply use another path parameter instead of you regex. Just name it whatever you want. [^/]+ is the default pattern, so something like this should work:

    <pattern value="/#{something}/#{entityId}"/>



    Removing brackets ( and ) leads to same log error.

    I narrowed the error down:

    The scope of this pattern is to wide.

    All ressources follow that pattern, thats why my converter for #{entityId} gets called also for resources since the pattern also matches those which result in a number exception in my converter since i assume an integer.


    Is also matched by it.

    Following workarounds:

    • 1. Exclude all other patterns matching in regexp.
    • 2. Change mapping of Resources. javax.faces.resource.
    • 3. Add new path separator like: <pattern value="/#{something}/e/#{entityId}"/>

    Thinking about 2 and/or 3.

    Site note:

    Now i maybe understand why amazon added /db/ between their product informations.

    • This reply was modified 8 years, 5 months ago by  djmj.

    Yeah, this is a problem people often run into. I typically recommend to either add some kind of prefix to the URL (essential you suggestion 3.) or to restrict the regular expressions of the path parameters. In your case you could for example restrict the first parameter to a string containing characters but no periods. Something like this:

    <pattern value="/#{ /[a-z]+/ something }/#{ /[0-9]+/ entityId }"/>

    See this part of the documentation for details:

    Our new project Rewrite, which is the successor of PrettyFaces, allows to handle such cases more easy. See Lincoln’s post here:

    If you want to learn more about how to migrate from PrettyFaces to Rewrite (and keeping your pretty-config.xml), have a look at the migration guide I wrote:

    Hope this helps. 🙂




    I will go for point 3, since excluding or restriction can lead to problems in the future with additional similar mappings.

    The complexity would increase greatly making it hard to maintain and performance wise it is also not such a good idea.

    I am also going to use rewrite programatically since all my possible query-parameter key values are hardcoded and duplicate definitions should be avoided.

    • This reply was modified 8 years, 5 months ago by  djmj.
Viewing 5 posts - 1 through 5 (of 5 total)

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

Comments are closed.