[英]JSTL c:choose c:when not working in a JSF page
考慮以下jstl選擇:
<c:choose>
<c:when test="#{AuthMsgBean.rw['2'] ne null}">
Display Text
</c:when>
<c:otherwise>
<ph:outputText id="pan" value="Component pan could not be created." />
</c:otherwise>
</c:choose>
AuthMsgBean = Bean
rw =地圖
'2'=關鍵
題:
當我只顯示#{AuthMsgBean.rw['2'] ne null}
值時,它顯示正常(true),但是一旦我嘗試將值解析為<c:when test=""/>
when標簽re - 就像測試總是假的一樣。
如果我在測試中輸入true( test="true"
),則顯示test="true"
顯示文本test="true"
。
是否可以在#{AuthMsgBean.rw['2'] ne null}
表達式之前評估<c:when>
標記?
如果是這樣,有解決方法嗎?
JSTL和JSF不像您期望的編碼那樣同步運行。 在JSF視圖構建時,它的JSTL首先從上到下運行,以生成僅包含JSF標記的視圖。 在JSF視圖渲染時,它是JSF,它從上到下再次運行以產生一堆HTML。
當JSTL輪到運行時, #{AuthMsgBean}
顯然不在范圍內。 當標記放在JSF迭代組件(如<h:dataTable>
時,就會發生這種情況。
無論如何,你不想在這里使用JSTL。 利用JSF rendered
attribtue。
<h:panelGroup rendered="#{not empty AuthMsgBean.rw['2']}">
Display Text
</h:panelGroup>
<h:outputText id="pan" value="Component pan could not be created." rendered="#{empty AuthMsgBean.rw['2']}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.