Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
802 views
in Technique[技术] by (71.8m points)

jsf 2 - c:choose not working in 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

Below, I have my page :

page.xhtml

<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>

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...