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

查看:34
本文介绍了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.

我测试了 在测试中定义的值是否返回true"?或假"确实如此.

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

我的问题是 永远不会被评估. 值总是被渲染.我错过了什么吗?是不是因为 <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天全站免登陆