how to hide all the suffix of the url

Splash Forums PrettyFaces Users how to hide all the suffix of the url

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

Viewing 15 posts - 1 through 15 (of 24 total)
  • Author
    Posts
  • #18121

    qeryui
    Participant

    I use the JSF 2 and glassfish to finish a web site.

    There are several pages on my web site. And I could change the suffix to .xxx

    but I could not remove all the suffix on the url.

    So I search and find pretttyFaces, I found it’s nice, however, I find I have to remove the suffix for each page

    <url-mapping id=”example”>

    <pattern value=”/examplepage” />

    <view-id value=”/examplepage.jsf” />

    </url-mapping>

    So could I remove all the suffix for all at once? Is it helpful to use PrettyFaces4? And I couldn’t find any tutorial about PrettyFaces4.

    2 I found chaning the page like ‘examplepage.jsf’ to ‘examplepage’, and it’s also to access the ‘examplepage.jsf’, then how to forbid it?

    #21864

    You could try to achieve this using the PrettyFaces rewrite engine:

    http://ocpsoft.com/docs/prettyfaces/3.3.2/en-US/html/inbound_rewriting.html

    Take a look at the manual. I guess something like this would work (untested):

    <rewrite match="/(.*).jsf" substitute="/$1" redirect="chain" />

    #21865

    Yes, you can use PrettyFaces 4 for this. You can take advantage of features of OCPsoft Rewrite (on which it is based.)

    You’ll just need to create a Rewrite configuration, and create the desired rule. However, PrettyFaces 4 has not yet been released (as of 12/14/2011), so just know that before you use it.

    See: http://ocpsoft.com/rewrite/ for how to get started with that.

    #21866

    qeryui
    Participant

    It seems to be that

    <rewrite match=”/(.*)” substitute=”/$1.jsf” redirect=”chain” />

    and i could use examplepage taking place of examplepage.jsf

    but sometimes it may occur that examplepage.jsf.jsf.jsf.jsf…..

    moreover the picture and ccs is invalid, maybe their url also be rewrote by the rule.

    #21867

    Yes, this rewrite rule your wrote will match EVERY request to the application including images and CSS files. You could try to modify the pattern to ignore images and CSS files but “don’t include” is very difficult to achieve in regular expressions. I think some users did something like this in the past. You could try to search the forums for this.

    What about something like this:

    <rewrite match=”/([^.]+)” substitute=”/$1.jsf” redirect=”chain” />

    This would work for all request that don’t contain a period character.

    #21868

    qeryui
    Participant

    http://ocpsoft.com/support/topic/rewriting-problem#post-1056

    I found this.

    and I use

    <url-mapping id=”global”>

    <pattern value=”/*” />

    <view-id> #{bean.getViewPath} </view-id>

    </url-mapping>

    @Named(“bean”)

    @RequestScoped

    public class Bean {

    public String getViewPath() {

    URL url = PrettyContext.getCurrentInstance().getRequestURL();

    String viewId = url.toString();

    if(viewId.endsWith(“.xhtml”) return viewId;

    else return viewId + “.xhtml”;

    }

    }

    But it is strange that <pattern value=”/*” /> only match http://localhost:8080/pair/*, and it doesn’t match any other urls.

    The <pattern value=”/#{*}” /> doesn’t work yet.

    Do I mistake that the regular expression could be used for the <pattern value=””> ??

    the Pretty I used is 3.3.2

    #21869

    Yes, the pattern is a regular expression. But /* means “any number of / characters”. Could you try:

    <url-mapping id="global">
    <pattern value="/.*" />
    <view-id> #{bean.getViewPath} </view-id>
    </url-mapping>

    #21870

    qeryui
    Participant

    ==!

    the regular expression doesn’t work…

    it’s so strange….

    #21871

    Actually now as I’m reading my post from yesterday again I realize that it won’t work this was. Regular expressions only work for path parameters. So you should try something like:

    <url-mapping id=”global”>

    <pattern value=”/#{ /.*/ path }” />

    <view-id> #{bean.getViewPath} </view-id>

    </url-mapping>

    #21872

    qeryui
    Participant

    thank you!

    <pattern value=”/#{ /.*/ path }” />

    this could match all the url.

    But when I use this pattern with the <view-id> #{bean.getViewPath} </view-id>,

    it will occur the 500 with the exception:

    javax.servlet.ServletException: PWC1232: Exceeded maximum depth for nested request dispatches: 20

    And the it wouldn’ enter the breakpoint in the bean.

    If

    <pattern value=”/faces/index.xhtml” />

    <view-id> #{bean.getViewPath} </view-id>

    is used,

    it will work well.

    #21873

    Which version of PrettyFaces are you using?

    You should perhaps try to avoid getting the URL from the PrettyContext and instead use a path parameter. Something like this:

    <url-mapping id="global">
    <pattern value="/#{ /.*/ bean.url }" />
    <view-id> #{bean.getViewPath} </view-id>
    </url-mapping>

    @Named("bean")
    @RequestScoped
    public class Bean {

    private String url;

    public String getViewPath() {
    if(url.endsWith(".xhtml") return url;
    else return url + ".xhtml";
    }

    /* getter + setter */

    }

    #21874

    qeryui
    Participant

    I use 3.3.2.

    I will try it later

    thank you

    #21875

    Just to explain why you shouldn’t use PrettyContext to get the URL: The PrettyContext returns always the original URL that was received from the browser. After the first call of your dynaview method the resulting viewID will be internally forwarded in the container. The forwarded requests will hit the PrettyFilter again and will match the URL pattern again. So your dynaview method will be called again. If you use the PrettyContext to obtain the URL you will get the original URL again (that one you already got in the first call) and so you will get into an endless loop.

    #21876

    qeryui
    Participant

    Oh,there’re something wrong with the regular expression charachter of “.”

    if

    <pattern value=”/#{ /.*/ bean.url }” />

    is used, /.*/ couldn’t match any url, and exception would occur

    if

    <pattern value=”/#{ /a*/ bean.url }” />

    is used, it works well

    if

    <pattern value=”/#{ /a.*/ bean.url }” />

    is used, it works well, it would match url like “/asdds” and so on

    so, when the character of “.” is put the ahead of the #{ //}, it may lead something wrong

    #21877

    Which exception occurs in the first example. Could you post the stacktrace?

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

You must be logged in to reply to this topic.

Comments are closed.