Search code examples
javajsfprimefaceswildfly

change url context path


Im working with JSF, primefaces, Java, and server wildfly. My question is:

I have a interface that is shown in the contextpath:

localhost:8080/public/page/validation.xhtml

Is there a way to change the context path to just:

localhost:8080/validation

Is this a thing that can be change at code level or is something of the server?

Thanks


Solution

  • The feature you are requesting is called URL rewriting and there are several ways how to achieve the desired behaviour.

    However, as you are already using JSF, the most convenient is probably going to be PrettyFaces (https://www.ocpsoft.org/prettyfaces/)

    With that, you can easily define URL mapping rules and have the prettyFaces servlet handle the rewriting:

    <url-mapping id="validation">
        <pattern value="/validation" />
        <view-id value="/public/page/validation.xhtml" />
    </url-mapping>
    

    Check the documentation for more info.