Find the Context Path with JSF
Published September 22, 2015
Sometimes JSF does not have a component that will produce a particular type of HTML element. That’s not a problem but, I always forget the three method deep route to the context path. I always find I have to work through an IDE’s code completion tool to find the application’s path.
Here it is for next time:
#{facesContext.externalContext.requestContextPath}
A shorter version:
#{request.contextPath}
Just for completeness here is the JSP version:
${pageContext.request.contextPath}
And finaly, the scriptlet version:
<%
String root = pageContext.getRequest().getServletContext().getContextPath();
%>
If you know any more please do leave a comment.