Move URL parameter position

Splash Forums PrettyFaces Users Move URL parameter position

This topic contains 2 replies, has 2 voices, and was last updated by  Lincoln Baxter III 6 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17844

    trivial2k
    Participant

    I’ve tried many ways but still can’t figure out how to do the following. Could somebody give me a hand?

    What I want is:

    Browser URL input is http://www.xxx.com/cutegirl/*.*/*.jsf

    to be mapped to http://www.xxx.com/*.*/*.jsf?username=cutegirl

    I know if will work if I write a rule for every JSF file. Do I have to specify the JSF file one by one? Is there any convenient way to have a generic configuration?

    Thank you very much.

    #20569

    Hey @trivial2k,

    You can use a global rewrite rule for something like this, notice you would need two rules, one rule if there are no incoming query parameters, and another rule if there are:

    <rewrite match="/^(cutegirl)(/.*/.*.jsf)$" substitute="$2?username=$1" />

    <rewrite match="/^(cutegirl)(/.*/.*.jsf?.*)$" substitute="$2&username=$1" />

    Which should do what you want:

    http://www.xxx.com/($1)($2/*.*/*.jsf) -> http://www.xxx.com/*.*/*.jsf?username=cutegirl

    I haven’t tested these specific rules, but they would look something like what I have written, using regular expressions:

    This is equivalent to:

    String newURL = ((String) request.getURI() + "?" + request.getQueryString()).replaceAll(match, substitute);

    You can read more about regular expressions here:

    http://ocpsoft.com/opensource/guide-to-regular-expressions-in-java-part-1/

    #20570

    I should add that you are correct, the ‘cleaner’ way to do this would be to write a url-mapping for each page on which you wish to perform the operation.

    There is currently no way to specify a global url-mapping, however, perhaps the parent URL-mapping functionality would be of interest:

    http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html/Configuration.html#config.mapping.parents

    The problem with global mappings is that they are not in fact a true mapping, they are more of a rewrite rule. It may however be beneficial to support the url/pattern/#{param} syntax in rewrite rules. I will add an issue for this:

    http://code.google.com/p/prettyfaces/issues/detail?id=80

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

You must be logged in to reply to this topic.

Comments are closed.