use*_*662 6 jsp jsp-tags custom-tags
我必须是盲人或使用错误的搜索词,因为我无法找到一个好的答案.
我有两个自定义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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1437 次 |
| 最近记录: |