我一定是盲人或使用了错误的搜索词,因为我找不到一个好的答案。
我有两个自定义 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>