RewriteRule to PrettyFaces.config

Splash Forums PrettyFaces Users RewriteRule to PrettyFaces.config

Tagged: 

This topic contains 15 replies, has 3 voices, and was last updated by  mfe_ 2 years, 9 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #25238

    mfe_
    Participant

    Hello,

    I have to convert my current .htaccess entry from

    RewriteRule ^(.*?)\.html index.php?filterrecipename=$1 [PT]

    to the pretty-config.xml.

    I did this:


    But I only get a 404 Error message when accesing for example http://localhost:8080/wie-koche-ich/Spaetzle.html.

    #25244

    Your pattern is incorrect. Please note that PrettyFaces XML configuration requires a specific format. The documentation describes this here: http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.pathparams.regex

    You may find Rewrite to be a simpler configuration method: http://ocpsoft.org/rewrite/docs/configuration/mapping

    #25256

    mfe_
    Participant

    Is there a way to get the compiled or generated regex of,

    <url-mapping id=”viewRecipe”>
    <pattern value=”/{# /(.*?) }” />
    <view-id value=”viewRecipe.jsf” />
    </url-mapping>

    because I’m not able to get it converted.

    #25257

    First, your pattern is still incorrect. Try the following:

    <url-mapping id=”viewRecipe”>
    <pattern value=”/#{ /(.*?)/ url }” />
    <view-id value=”viewRecipe.jsf” />
    </url-mapping>
    

    Second, to get the compiled pattern. Look at PrettyContext.getCurrentInstance().getCurrentMapping()

    #25259

    mfe_
    Participant

    Thanks for your reply. I’m a little bit confused, because I tried to improve my pattern so that it will work only on characters and with “%20”.
    For example SPAETZLE%20OHNE%20EI.html

    <url-mapping id=”viewRecipe”>
    <pattern value=”/#{ /([a-zA-Z_%0-2]*\.html)/ name }” />
    <view-id value=”/viewRecipe.jsf” />
    </url-mapping>

    But I’m stuck, because I can’t get the pattern with PrettyContext.getCurrentInstance().getCurrentMapping() when I recive a 404 Page ( I only have “Bean Classes”, no “Servlets” or something else.) I checked the pattern at http://www.regexplanet.com/advanced/java/index.html and it seemed to be correct.

    • This reply was modified 2 years, 9 months ago by  mfe_.
    • This reply was modified 2 years, 9 months ago by  mfe_.
    #25261

    You may need to use \\. instead of \. for the dot character. Could you try this?

    #25272

    mfe_
    Participant

    I tried

    <pattern value=”/#{ /([a-zA-Z_%0-2]*\\.html)/ name }” />

    and called http://localhost:8080/wie-koche-ich/SPAETZLE%20OHNE%20EI.html but it results in a 404.

    I removed the “.html” pattern and tried this:

    <pattern value=”/#{ /([a-zA-Z_%0-2]*)/ name }” />

    and called http://localhost:8080/wie-koche-ich/SPAETZLE%20OHNE%20EI and got again a 404 🙁

    #25273

    Could you try these versions?

    <pattern value=”/#{ /[a-zA-Z_%0-2]+/ name }” />
    <pattern value=”/#{ /[a-zA-Z_%0-2]+\\.html/ name }” />
    
    #25274

    And if this still doesn’t work, could you create a minimal Maven project that reproduces this issue?

    #25275

    mfe_
    Participant

    Thanks, for your fast reply.

    I think I found the failure in the Regex. When removing the “%20” pattern the regex Rule works.
    Working Regex:

    <pattern value=”/#{ /([a-zA-Z]*\\.html)/ name }” />
    <pattern value=”/#{ /[a-zA-Z]+\\.html/ name }” />

    with: http://localhost:8080/wie-koche-ich/SPAETZLE.html

    So the question is how do I can add the “%20” to allow white spaces in the url.

    #25276

    Perhaps % has to be escaped? Try:

    <pattern value=”/#{ /([a-zA-Z\\%0-2]*\\.html)/ name }” />

    It is also possible that the regular expression is tested AFTER %20 is decoded. So you could try a simple space in the regex:

    <pattern value=”/#{ /([a-zA-Z ]*\\.html)/ name }” />

    #25277

    mfe_
    Participant

    Thanks a lot Christian

    <pattern value=”/#{ /([a-zA-Z ]*\\.html)/ name }” />

    worked for me with http://localhost:8080/wie-koche-ich/SPAETZLE%20OHNE%20EI.html 🙂

    #25278

    Glad you got it working! You gotta’ love Java’s double escaped Regexes 🙂

    #25297

    mfe_
    Participant

    I got something more:

     <url-mapping id="viewIngredient">
            <pattern value="/ingredient/#{ /([a-zA-Z ]*\\.html)/ ingredient }" />
            <view-id value="/viewIngredient.jsf" />
        </url-mapping>

    This regex works fine.
    In my viewIngredient.jsf I have the following viewParameter

            <f:metadata>
                <f:viewParam name="ingredient" value="#{IngredientBean.ingredient}" converter="#{ingredientStringConverter}" required="true" maxlength="150"></f:viewParam>
            </f:metadata>

    Whenever I call http://localhost:8080/wie-koche-ich/ingredient/SPAETZLE%20OHNE%20EI.html my viewParameter ingredient and the converter recives “SPAETZLE OHNE EI.html” as string. So I asked myself if there is a way to tell prettyfaces to assign the parameter without the “.html”?
    In this example the viewParam ingredient should only contain the value “SPAETZLE OHNE EI”.

    If this can be done with prettyfaces this would be really great!

    Best regards

    • This reply was modified 2 years, 9 months ago by  mfe_.
    #25299

    You could try changing your parameter pattern to the following:

    <pattern value="/ingredient/#{ /([a-zA-Z ]*)/ ingredient }.html" />

    This might work.

    Otherwise, check out http://ocpsoft.org/rewrite/ – which is the lower-level java-based URL-rewriting framework on which PrettyFaces is built. It will definitely let you do what you need if this does not work 🙂

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.

Comments are closed.