Rewrite spaces in URL

Splash Forums PrettyFaces Users Rewrite spaces in URL

This topic contains 6 replies, has 2 voices, and was last updated by  Christian Kaltepoth 10 years, 3 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #18040



    I’m using JSF2 with PrettyFaces 3.3.0. I have list of categories generated automatically. Category name is included as path parameter. It’s very simple pattern, like pattern=/#{name}/. However spaces in url are encoded as %20, so it dosen’t look good.

    How can I write pretty rewrite rule to replace spaces to _. I want do this only on “client” side, so in backing bean I still have spaces in #{name}.


    Replacing spaces with underscores is possible, but the other way around wont work, because you cannot distinguish whether an underscore is a space or a just an underscore.

    With 3.3.0 you could implement a custom rewrite processor for something like this. See the documentation for details.

    In 4.0.0-SNAPSHOT we support custom JSF converters you can attach to individual path and query parameters. Here you cans simply implement a JSF converter that converts the string to the “url representation” and the other way around.


    BTW: Perhaps %20 isn’t “pretty”, but it’s the correct representation of an space character in URLs.

    Another idea. You could simply add another property to your category model object containing some kind of “URL category name”. For example the name lowercased and all spaces replaced by underscores. If you could also make sure that the URL category name is unique, you can easily use it in URL parameters because you can lookup a category by the unique name from the database.



    Thanks, for now I’ll add another property. When 4.0.0 is to be released? Is there any documentation for 4.0.0-SNAPSHOT?


    I cannot give any specific date for the 4.0.0 release. And unfortunately there is currently no documentation automatically deployed from the snapshots. Currently the only way to obtain the documentation is to clone the git repository and build it manually.

    Doing the conversion in special getters/setters will definitively work. However if you want a more complete solution you should take a look at the custom rewrite processors.



    Could you post simple example how to use conventers for path parameters?

    This is not working for me:

    @URLMapping(id = "page",
    viewId = "/page.html",
    pattern = "/#{name}-#{id}/",
    public class TestConv implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
    return value.toUpperCase();

    public String getAsString(FacesContext context, UIComponent component, Object value) {
    return value.toString().toUpperCase();

    #{name} is not mapped to backing bean, it is only set by f:param inside h:link for seo purposes only

    Should this converter be executed before creating link in html source?


    Hey m1m,

    sorry, but converters currently don’t work correctly when using <h:link> and <pretty:link> in 4.0.0-SNAPSHOT. There is still some discussion on how to implement this. See this ticket for details:

    As I said 4.0.0 is currently in heavy development. So features like this aren’t completely usable at the moment. Sorry! :(

    At the moment I can only suggest to take a look at custom rewrite processors to implement such a conversion like you want it.


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

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

Comments are closed.