Search code examples
jsfpathidentifier

Identifying path of current JSF / XHTML page


I need something that will uniquely identify my JSF (XHTML) page.

I know that I have:

String URI = servletRequest.getRequestURI();

This gives my full path, but that doesn't help if I use PrettyFaces or any other URL changing library.


Solution

  • You can use UIViewRoot#getViewId() for this:

    String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
    

    It's also available in EL as follows:

    #{view.viewId}