【发布时间】:2014-07-30 09:59:22
【问题描述】:
我一定是盲目的或使用了错误的搜索词,因为我无法找到一个好的答案。
我有两个自定义 JPS 标记文件。一个将嵌套在另一个中。如何从子标签内部访问父标签中的属性?
一种解决方法是向请求范围添加一个变量,但我不喜欢这个选项,它可能会导致一些问题。有没有更直接的选择?
谢谢!
<%-- OuterTag.tag --%>
--------------------------------------
<%@tag %>
<%@attribute name="color" required="true" %>
<c:set var="color" value="${color}" scope="request" /> <%-- I'm trying to avoid doing this --%>
<div>
<jsp:doBody/>
</div>
<%-- InnerTag.tag --%>
--------------------------------------
<%@tag %>
<p style="background-color: ${parent.color}"/> <%-- I want to do something like this --%>
<%-- Example Usage --%>
--------------------------------------
<custom:OuterTag color="red">
<custom:InnerTag/>
<custom:InnerTag/>
<custom:InnerTag/>
</custom:OuterTag>
【问题讨论】:
-
没有接受者?这是一个愚蠢的问题吗?似乎它应该如此简单。我以为它会在 15 分钟内得到答复。大声笑
标签: jsp jsp-tags custom-tags