JSTL c:选择c:不在JSF页面中工作 [英] JSTL c:choose c:when not working in a JSF page

查看:117
本文介绍了JSTL c:选择c:不在JSF页面中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下 jstl 选择:

Consider the following jstl choose:

<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标签重新起作用,好像测试始终为假。

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.

如果我在测试中输入了真( test =true),则显示显示文本。

If I put true in the test (test="true") the Display Text is displayed.

可能是< c:when> 标记在之前评估#{AuthMsgBean.rw ['2'] ne null } 表达式?

如果有,是否有解决方法?

If so, is there a workaround?

推荐答案

JSTL和JSF不会像编码时那样同步运行。在JSF视图构建时,它是JSTL,它首先从上到下运行,以生成仅包含JSF标记的视图。在JSF视图渲染时,JSF从上到下再次运行以产生一堆HTML。

JSTL and JSF do not run in sync as you'd expect from coding. During JSF view build time, it's JSTL which runs from top to bottom first to produce a view with only JSF tags. During JSF view render time, it's JSF which runs from top to bottom again to produce a bunch of HTML.

显然#{AuthMsgBean} <当JSTL轮到运行时,范围内不存在/ code>。当标记放在JSF迭代组件中时可能会发生这种情况,例如< h:dataTable>

无论如何,你不想在这里使用JSTL。使用JSF 渲染 attribtue。

Regardless, you do not want to use JSTL here. Make use of the 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']}" />



参见:




  • 有条件地展示JSF组件

  • See also:

    • Conditionally displaying JSF components
    • 这篇关于JSTL c:选择c:不在JSF页面中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆