Is a better way to generate absolute links in JSF 2.0 ? Right now I’m using <h:outputLink/> in that ugly way with #{facesContext.externalContext.requestContextPath} like below. I don’t want to use JSTL and <c:url />
<h:outputLink value="#{facesContext.externalContext.requestContextPath}/pages/home.jsf">Home</h:outputLink>
You can shorten
#{facesContext.externalContext.requestContextPath}to#{request.contextPath}. You can even get rid of it to use HTML<base>tag instead.In this particular case, better is to use
<h:link>instead. It can take a context-relative navigation case path inoutcomeattribute:JSF will take care about adding the right context path and
FacesServletmapping while generating the<a>element:See also: