I'm using the following to get a help document in our app. My problem is that while the <h:graphicImage>
evaluates the context path correctly, the h:outputLink
evalutates it to nothing. I have tried using both $
and #
in the h:outputLink
because I understand they have different evaluation times.
What is the difference in how the two EL expressions evaluate?
<h:outputLink value="${pageContext.servletContext.contextPath}/services/help.pdf">
<h:graphicImage
url="${pageContext.servletContext.contextPath}/images/help.png"
alt="Online Help"/>
</h:outputLink>
That the context path doesn't appear in
<h:outputLink>
suggests that you're actually using Facelets instead of JSP. The${pageContext}
doesn't exist in Facelets at all. It's specific to legacy JSP. Both expressions have just evaluated to an empty string. There is thus no difference between them at all.That the context path appears in
<h:graphicImage>
is fully expected. This is automatically included by the component itself. In fact, the entire expression is superfluous and the following should work as good.The
<h:outputLink>
does indeed not automatically include the context path. Only the<h:link>
does that. You'd need to include it yourself. In Facelets, you can use#{request}
to get a handle toHttpServletRequest
which in turn has agetContextPath()
as well (and which is used by<h:graphicImage>
under the covers).Try this #{facesContext.externalContext.requestContextPath} i hope this can help you also check this link link text
Regards, Sergio Valdez