Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EL context path evaluation difference between outputLink and graphicImage

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>
like image 987
Adam Avatar asked Nov 10 '10 20:11

Adam


2 Answers

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.

<h:graphicImage url="/images/help.png" alt="Online Help"/>

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 to HttpServletRequest which in turn has a getContextPath() as well (and which is used by <h:graphicImage> under the covers).

<h:outputLink value="#{request.contextPath}/services/help.pdf">
like image 185
BalusC Avatar answered Nov 05 '22 21:11

BalusC


Try this #{facesContext.externalContext.requestContextPath} i hope this can help you also check this link link text

Regards, Sergio Valdez

like image 40
Sergio Valdez Avatar answered Nov 05 '22 20:11

Sergio Valdez