基于标签变量评估其主体的自定义标签 [英] Custom tag that evaluates its body based on the variables of the tag

查看:67
本文介绍了基于标签变量评估其主体的自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,现在我猜这是针对硬JSTL向导的;-)

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>

不应设置outsideVar变量,并且标记的主体应类似于<jsp:include/>

The outsideVar variable should not be set and the body of the tag should behave like the content of a <jsp:include/>

这是这个问题的一个更具体的问题: 是否可以创建本地页面JSP中的范围? 该链接还说明了此问题的背景.

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.

推荐答案

您的自定义标签可以在评估正文之前抓取并删除所有页面属性,然后清除并还原.

Your custom tag can grab and remove all page attributes before evaluating the body, and then clear and restore afterwards.

这篇关于基于标签变量评估其主体的自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆