[英]JSTL c:choose c:when not working in a JSF page
Consider the following jstl choose: 考虑以下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 AuthMsgBean = Bean
rw = Map rw =地图
'2' = Key '2'=关键
Question: 题:
When I simply display the #{AuthMsgBean.rw['2'] ne null}
value it displays fine (true), but once I try to parse the value to the <c:when test=""/>
the when tag re-acts as if the test is always false. 当我只显示
#{AuthMsgBean.rw['2'] ne null}
值时,它显示正常(true),但是一旦我尝试将值解析为<c:when test=""/>
when标签re - 就像测试总是假的一样。
If I put true in the test ( test="true"
) the Display Text is displayed. 如果我在测试中输入true(
test="true"
),则显示test="true"
显示文本test="true"
。
Could it be that the <c:when>
tag is evaluated before the #{AuthMsgBean.rw['2'] ne null}
expression? 是否可以在
#{AuthMsgBean.rw['2'] ne null}
表达式之前评估<c:when>
标记?
If so, is there a workaround? 如果是这样,有解决方法吗?
JSTL and JSF do not run in sync as you'd expect from coding. JSTL和JSF不像您期望的编码那样同步运行。 During JSF view build time, it's JSTL which runs from top to bottom first to produce a view with only JSF tags.
在JSF视图构建时,它的JSTL首先从上到下运行,以生成仅包含JSF标记的视图。 During JSF view render time, it's JSF which runs from top to bottom again to produce a bunch of HTML.
在JSF视图渲染时,它是JSF,它从上到下再次运行以产生一堆HTML。
Apparently the #{AuthMsgBean}
is not present in the scope when it's JSTL's turn to run. 当JSTL轮到运行时,
#{AuthMsgBean}
显然不在范围内。 That can happen when the tags are placed inside a JSF iterating component such as <h:dataTable>
. 当标记放在JSF迭代组件(如
<h:dataTable>
时,就会发生这种情况。
Regardless, you do not want to use JSTL here. 无论如何,你不想在这里使用JSTL。 Make use of the JSF
rendered
attribtue. 利用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.