dynamic url

Splash Forums PrettyFaces Users dynamic url

This topic contains 12 replies, has 3 voices, and was last updated by  eastl 8 years, 4 months ago.

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


    Hey all,

    is it possible to build a prettyfaces regex expression to cover dynamic long urls, example:

    and many more..

    till yet, i have to declare many of these…
    <pattern value=”/#{katName0}/#{katName1}/#{katName2}/”></pattern>
    <view-id value=”/kategorien.jsf”></view-id>
    <pattern value=”/#{katName0}/#{katName1}/#{katName2}/#{katName3}/”></pattern>
    <view-id value=”/kategorien.jsf”></view-id>

    and the same for content Urls
    <pattern value=”/#{katName0}/#{content}”></pattern>
    <view-id value=”/artikelDetails.jsf”></view-id>

    <pattern value=”/#{katName0}/#{katName1}/#{content}”></pattern>
    <view-id value=”/artikelDetails.jsf”></view-id>

    is there a way to shrink this ?
    (and how can i get the Parameters)

    thanks for your time!


    You could modify the regular expression used to match a path parameter in a way that it captures the whole path:

      <pattern value=”/#{  /.+/ katName }/”></pattern>
      <view-id value=”/kategorien.jsf”></view-id>

    Then you could split the full category string into the individual category names manually.




    Hey Christian,

    this works like charm for categories, thanks!

    but not for article detail pages like:
    this should use the view-id: /article.jsf

    i also need other definitions like:
    this should use the view-id: /content.jsf

    till yet, if i paste /info/content-pages-like-imprint
    i get redirected to /article.jsf

    many thanks christian!



    got it working

        <pattern value="/info/#{contentController.viewPage}" /> 
        <view-id value="/META-INF/templates/layout.jsf" />
      	<pattern value="/#{ /.+/ katName }/"></pattern>
     	<view-id value="/kategorien.jsf"></view-id>
      	<pattern value="/#{ /.+/ katName }/[^.]+$"></pattern>
     	<view-id value="/artikelDetails.jsf"></view-id>

    categorie directorys like:
    -> works -> viewID /kategorien.jsf will be used

    article detail Pages like:
    -> works -> viewId artikelDetails.jsf will be used

    info Pages like:
    -> works -> viewID /META/templates/layout.jsf will be used

    System Pages like:
    -> works -> cos regex pattern exclude the last end of the url if it contains a dot

    • This reply was modified 8 years, 4 months ago by  senceffm.

    Nice to hear you got it working.

    The difficult task for such mappings is to define them so they don’t overlap and don’t match too much. The category mapping is a good example of this. The pattern /#{ /.+/ katName }/ looks fine because of the trailing slash. But if you remove the tailing slash you have /#{ /.+/ katName } which will also match URLs like /styles/my-style.css.



    hey chris,

    thats true, but this is our daily business 🙂 and the reason why i had to add a “not contains” expression in:
    <pattern value="/#{ /.+/ katName }/[^.]+$"></pattern>
    else i would get in trouble with your postet .css example

    but one exception keep me up working:

    if there is a “ajax” anchor link with a “#” in href, ajax breks with this definition:
    <pattern value=”/#{ /.+/ katName }/[^.]+$”></pattern>

    (html output)

    <a onclick="mojarra.jsfcljs(document.getElementById('j_idt50'),{'j_idt50:j_idt59':'j_idt50:j_idt59'},'');return false" href="#">add to basket</a>

    if i hit the ajax link, i get a 404:
    (“NetworkError: 404 Not Found – http://shop-dev/harddisks/%5B%5E.%5D+$“)
    (orign: url -> http://shop-dev/harddisks/18606-harddisks-8602)
    do you know what occours the exception ?

    thanks christian for your time


    Could you try to wrap the trailing regular expression in a parameter like this:

    <pattern value=”/#{ /.+/ katName }/#{ /[^.]+/ something }”></pattern>

    By the way, you can work around such problems by using some unique prefix in the URL. Something like Amazon does in the URLs:


    Note the /gp/product/ prefix. This would essentially be a mapping like this:

      <pattern value="/gp/product/#{ean}/"></pattern>
      <view-id value="/kategorien.jsf"></view-id>


    until yet i’m using a unique prefix in the URL, but i wanna try to get it work without any work arounds 🙂
    its not so easy but it must be possible, cos many shop systems (php based and .htaccess) can do it,
    why should a good combined system like “jsf2 + prettyfaces” shouldn’t accomplish that 😉


    Yeah, that’s true. 🙂

    One more thing to take into account is that the order of rules matter, because mappings are processed in the same order as they appear in the file. The first rule that matches wins. So if there are URLs that may match multiple rules, the more specific rule should be placed before the more general one.



    Hey Christian,

    thanks, works like charm right now, ajax is working also fine.
    could you please explain in short what differs to my definition ?

    the only thing i had to adjust was my own autocomplete component
    URL: /service/ajaxHandler
    cos the URL structure equals to the article url.

    so i only had to change the ServletPath to:
    URL: /service/ajaxHandler.ws (i used ws for WebService)
    now all working as expected (till yet :P)

    thanks chris you adviced me very well!


    Yeah, looks like your autocomplete URL was rewritten, and therefore requests to it where forwarded to the JSF page, which of cause failed.

    Glad to hear you got it working… 🙂




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

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

Comments are closed.