问题
Ok, now this is something for the hard core JSTL wizards I guess ;-)
I would like to have a tag whose body does not substitute the variables of the surrounding page. It should only take the variables into account that have been specified in the body of the tag or in the tag itself like this:
<c:set var="outsideVar" value="outside value"/>
<a:component>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<div data-component-id="9">
<c:set var="componentId" value="9"/>
<c:set var="path" value='${abc:getCurrentPath()}_${componentId}'/>
<c:set var="resource" value='${abc:getResourceFromPath(path)}'/>
<c:set var="val" value="${resource.getValue('paragraphValue')"/>
<p>${fn:escapeXml(val)}</p>
${outsideVar}
</div>
</a:component>
The outsideVar
variable should not be set and the body of the tag should behave like the content of a <jsp:include/>
This is a more specific question of this one: Is it possible to create a local page scope in a JSP? The link also explains the background of this question.
回答1:
Your custom tag can grab and remove all page attributes before evaluating the body, and then clear and restore afterwards.
来源:https://stackoverflow.com/questions/32404445/custom-tag-that-evaluates-its-body-based-on-the-variables-of-the-tag