我必須是盲人或使用錯誤的搜索詞,因爲我無法找到一個好的答案。如何訪問嵌套JSP標記文件中的父屬性?
我有兩個自定義的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分鐘內回覆。大聲笑 – user3311662