Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...