Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access JSP Context inside custom EL function

Tags:

jsp

el

How can I access the JSP context inside a custom EL function.

like image 977
Viren Avatar asked Mar 15 '11 15:03

Viren


1 Answers

You have to explicitly include it as an argument to the method that implements your EL function.

Java method that implements EL function:

public static Object findAttribute(String name, PageContext context) {
    return context.findAttribute(name);
}

TLD entry for EL function:

<function>
    <name>findAttribute</name>
    <function-class>kschneid.Functions</function-class>
    <function-signature>java.lang.Object findAttribute(java.lang.String, javax.servlet.jsp.PageContext)</function-signature>
</function>

Usage in JSP:

<%@ taglib prefix="kfn" uri="http://kschneid.com/jsp/functions" %>
...
<c:if test="${empty kfn:findAttribute('userId', pageContext)}">...</c:if>
like image 63
kschneid Avatar answered Oct 21 '22 03:10

kschneid