Question

Is there a way to use something like deferred EL in JSP 2.0 / J2EE 1.4? The idea is to pass a test to a tag file and have it display an item in a list (or not) based on the value of the expression. Basically, I'd like to do something like this:

JSP:

<x:myTag items="${myCollection}" test="${item.visible}"/>

myTag.tag

<c:forEach var="item" items="${collection}">
    <c:if test="${test}">
        ${item}
    </c:if>
</c:forEach>

Upgrading our JSP container is not an option. Any ideas?

Update:

I tried doing this with JSP fragments, but the EL in the fragment was evaluated once in the JSP, rather than once per iteration in the tag.

Was it helpful?

Solution

You should be able to do this with jsp fragments. I believe it will not be the extremely elegant solution you would appreciate, but it does allow the execution of the expression to be deferred until inside the tag.

Edit: You could check out the variable with the "name-given" setting.

(I will readily admit I did something like what you're trying to do about 2 years ago. I have not touched it since. I remember I thought it was quite arcane)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top