c:选择在JSF中不工作 [英] c:choose not working in JSF

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

问题描述

我有三个值,并且我希望在前两个值的情况下呈现一个组件,而在第三个值的情况下呈现另一个组件

I have three values and I want one component to be rendered in the case of first two values and another component for the third value

下面,我有我的页面:

<ui:repeat value=#{bean.value} var="data">
<c:choose>
 <c:when  test="#{data.thirdValue == 'content'}">
   <h:outputText value="Wrong value"/>
 </c:when>
 <c:otherwise>
  Correct!
 </c:otherwise>
</c:choose>
</ui:repeat>

这是我的页面的定义方式.我还添加了以下命名空间:xmlns:c="http://java.sun.com/jsp/jstl/core.

This is how my page is defined. I have also added the following namespace : xmlns:c="http://java.sun.com/jsp/jstl/core.

我测试了在<c:when>的测试中定义的值是否返回"true"或"false",并且确实如此.

I tested whether, the value defined inside test for <c:when> returns "true" or "false" and it does.

我的问题是<c:when>从未被评估过. <c:otherwise>值始终呈现.我想念什么吗?是因为<ui:repeat>中的条件渲染导致了对when的不评估?

My problem is that the <c:when> is never evaluated. The <c:otherwise> value is always rendered. Am I missing something? Is it because of the the conditional rendering being inside <ui:repeat> that the when is not evaluated?

任何帮助将不胜感激.预先感谢

Any help will be most appreciated. Thanks in advance

推荐答案

您需要删除c:choose,因为正如@Jens在评论中指出的那样,它们在不同的阶段进行处理.您可以将JSTL与JSF一起使用,但是必须遵守解决它们的顺序.读了BalusC的精彩回答后,他感到震惊.

You need to remove the c:choose, because as @Jens stated on the comments, they are processed in different phases. You can use JSTL in tandem with JSF, but have to respect the order they are resolved. read the fine answers by BalusC, he rocks.

根据需要,您可以使用 rendered属性,有条件地输出您的文本:

As for your needs, you can use the rendered attribute, to conditionally output your text:

<ui:repeat value="#{bean.value}" var="data">
    <h:outputText rendered="#{data.thirdValue == 'content'}" value="Wrong value"/>
    <h:outputText rendered="#{data.thirdValue != 'content'}" value="Correct!"/>
</ui:repeat>

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

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