tags:

views:

274

answers:

1

I'm trying to use the following snippet inside my tag file:

<%@ attribute name="content" fragment="true"%>
...
<c:set var="part" value="content"/>
<jsp:invoke fragment="${part}" var="partValue"/>
...

and compiler gives me the following error:

Syntax error, insert ") Statement" to complete IfStatement

so as I understand it's not permitted to use el expression in fragment attribute. Could somebody point me to this restriction in specification? Or give advice how to invoke content of fragment if name of fragment I calculate at runtime

+1  A: 

Technically the fragment attribute is not a rtexprvalue, which can be seen from the schema; which means It's evaluated at compile time.

There is really only a very limited set of use cases for what you're trying to achieve. Most likely you want to supply multiple fragments to a tag file and let some conditional decide which tag to output.

<c:choose>
    <c:when test="${condition1}"><jsp:invoke fragment="frag1"/></c:when>
    <c:otherwise><jsp:invoke fragment="frag2"/></c:otherwise>
</c:choose>
krosenvold