Notes of a (Java) developer

JSTL (and EL)

Software developer Programmer

Custom EL functions

The first official documentation available on the topic is The Java EE 5 tutorial. The JSTL specification allows to define custom functions. This is done easily with simple static methods specified in a Tag Library Definition (tld) file. For example, a file located at /WEB-INF/tags/my-functions.tld:

<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns=""
        <function-signature>java.lang.String myMethodSignature( java.lang.String )</function-signature>

Can be loaded by the JSP that way (the URI can be improved);

<%@ taglib prefix="mine" uri="/WEB-INF/tags/my-functions.tld" %&gt>

Then the static method is called with a simple expression using the specified prefix:

${mine:myMethod('my string value')}

"fn" (functions)

There is a problem in testing the content of an HTTP request URL: the HttpServletRequest method returns a StringBuffer. The fn:contains(.., ..) function accepts only strings. Using the getRequestURL() result as an argument works fine. But this is not static-type conform. Here the Eclipse IDE Web page validation complains.

In order to code in a static-type way, the solution is to set the StringBuffer in a variable to transform it into a string. Then the function can be used properly without any validation problem:

<c:set var="requestUrl" value="${pageContext.request.requestURL}" />
<c:if test="${fn:contains(requestUrl, '...')}">

"fmt" (messages)

Using a message tag (fmt) with param children, I had to escape quotes unless the message would not include the parameters.

Java Web