Search code examples
javajsf-2url-rewritingprettyfaces

Get current page name with JSF/PrettyFaces


i am using PrettyFaces as url rewrite library as follows:

@URLMappings(mappings = {
        @URLMapping(id = "page1", pattern = "/page1", viewId = "/faces/pages/page1.xhtml"),
        @URLMapping(id = "page2", pattern = "/page2", viewId = "/faces/pages/page2.xhtml") })

i can get the viewId as follows:

String viewId = facesContext.getViewRoot().getViewId();

which will return something like: /faces/pages/page1.xhtml

i was wondering if there's a direct way to get the pattern or the id of the view to return something like page1 or i have to use substring on the above code for getting the viewId?


Solution

  • Yep :) Just call:

    PrettyContext.getCurrentInstance().getCurrentMapping().getId();
    

    or, .getPattern() or etc...

    Cheers :)