< c:choose>在数据表中不起作用 [英] <c:choose> not working in datatable

查看:129
本文介绍了< c:choose>在数据表中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据表中,当满足特定条件(启用链接)时,需要转换一个值:

In a datatable a value needs to be translated when a certain condition applies (link enabled):

<h:outputLink disabled="#{pluginSummary.linkEnabled}" target="_blank"  value="http://www.nessus.org/plugins/index.php">
    <c:choose>
        <c:when test="#{not pluginSummary.isLinkEnabled()}" >
            <h:outputText value="#{pluginSummary.pluginid}"/>
        </c:when>
        <c:otherwise>
            <h:outputText value="#{texts[pluginSummary.pluginid]}"/>
        </c:otherwise>
    </c:choose>
    <f:param name="id" value="#{pluginSummary.pluginid}"/>
    <f:param name="view" value="single"/>
</h:outputLink>

但是奇怪的是,只有第一个条件适用,并且从来没有翻译.为了调试,我还添加了<h:outputText value="#{pluginSummary.isLinkEnabled()}/>,在那里看到了正确的和错误的条目,但是我的文本从未得到翻译.

But strangely only the first condition applies and there is never a translation. To debug I also added a <h:outputText value="#{pluginSummary.isLinkEnabled()}/> and there I see the different true and false entries, but I the text gets never translated.

有人知道c:choose是否在数据表中工作吗?我有什么选择?

Does anybody know, if c:choose works in a datatable? What are my alternatives?

推荐答案

JSTL标记和JSF标记不会像您期望的那样同步运行. JSTL标记在视图构建时运行,而JSF标记在视图渲染时运行.您可以将其可视化如下:JSTL首先从上到下运行,然后将生成的结果(没有任何JSTL标记!)移交给JSF,后者又从上到下运行,以为Web浏览器生成HTML.

JSTL tags and JSF tags doesn't run in sync as you'd expect from coding. JSTL tags runs during view build time and JSF tags runs during view render time. You can visualize it as follows: JSTL runs from top to bottom first and then hands over the generated result (without any JSTL tags!) to JSF which in turn runs from top to bottom again to produce HTML for the webbrowser.

我知道#{pluginSummary}被定义为数据表的var.在JSTL运行时,此变量不可用,因此在该点始终为null.

I understand that #{pluginSummary} is definied as var of the datatable. At the moment JSTL runs, this variable is not available, so it's always null at that point.

您需要改用JSF标记/属性.在这种情况下,您想使用JSF rendered属性.

You need to use JSF tags/attributes instead. In this particular case you want to use the JSF rendered attribute instead.

<h:outputText value="#{pluginSummary.pluginid}" rendered="#{not pluginSummary.linkEnabled}" />
<h:outputText value="#{texts[pluginSummary.pluginid]}" rendered="#{pluginSummary.linkEnabled}"/>

(请注意,我也将方法调用更改为属性,因为您无需传递任何参数,这很清楚)

这篇关于&lt; c:choose&gt;在数据表中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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