dynamic url

Splash Forums PrettyFaces Users dynamic url

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

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

    senceffm
    Participant

    Hey all,

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

    http://www.domain.de/seoKat1/
    http://www.domain.de/seoKat1/seoKat2/
    http://www.domain.de/seoKat1/seoKat2/seoKat3/
    http://www.domain.de/seoKat1/seoKat2/seoKat3/seoKat4/
    and many more..

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

    and the same for content Urls
    http://www.domain.de/seoUrlContentWithoutEndingSlash
    http://www.domain.de/seoKat1/contentWithoutEndingSlash
    http://www.domain.de/seoKat1/seoKat2/contentWithoutEndingSlash
    http://www.domain.de/seoKat1/seoKat2/seoKat3/contentWithoutEndingSlash
    <url-mapping>
    <pattern value=”/#{katName0}/#{content}”></pattern>
    <view-id value=”/artikelDetails.jsf”></view-id>
    </url-mapping>

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

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

    thanks for your time!

    #24872

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

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

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

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

    #24942

    senceffm
    Participant

    Hey Christian,

    this works like charm for categories, thanks!
    /categorie/

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

    i also need other definitions like:
    /info/content-pages-like-imprint
    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!

    #24944

    senceffm
    Participant

    EDIT:
    got it working

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

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

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

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

    System Pages like:
    /index.jsf
    or
    /checkout/basket.jsf
    -> works -> cos regex pattern exclude the last end of the url if it contains a dot

    • This reply was modified 2 years, 10 months ago by  senceffm.
    #24946

    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.

    #24947

    senceffm
    Participant

    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:
    http://shop-dev/harddisks/%5B%5E.%5D+$
    (“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

    #24948

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

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

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

    http://www.amazon.com/gp/product/B00B7N9CWG

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

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

    senceffm
    Participant

    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 😉

    #24951

    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.

    #24953

    senceffm
    Participant

    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!

    #24962

    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… 🙂

    #24984

    eastl
    Participant

    ??

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

You must be logged in to reply to this topic.

Comments are closed.