简体   繁体   English

jsp:invoke中的el表达式

[英]el expression in jsp:invoke

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. 因此,据我了解,不允许在fragment属性中使用el表达式。 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 或者给出建议,如果我在运行时计算出片段的名称,则如何调用片段的内容

Technically the fragment attribute is not a rtexprvalue, which can be seen from the schema; 从技术上讲,fragment属性不是rtexprvalue,可以从模式中看到它。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM