11

I have two strings that i need to compare, but even if they have the same values or different , it always enters the statement...

<c:when test="#{bean.name1 != bean.name2}">
     fields that are supposed to appear _only_ when name1 is different from name2
</c:when>
Moon13
  • 283
  • 1
  • 5
  • 15

6 Answers6

7

The problem is that you probably did not wrap the when in a choose tag.

if you have:

    <c:choose>
    <c:when test="${bean.name1 != bean.name2}">
        fields that are supposed to appear _only_ when name1 is different from name2
    </c:when>
</c:choose>

It will work

John Vint
  • 39,695
  • 7
  • 78
  • 108
4

Should it be ?

<c:if test="#{bean.name1 != bean.name2}">
     // code
</c:if>

EDIT : <c:when> is supposed to be inside <c:choose>. Cannot ask why, that is just the syntax. It is like asking why if will not work in place of switch in C/C++/Java. They are just different animals.

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
0

Does it make any difference if you do this:

<c:when test="${bean.name1 != bean.name2}">
     fields that are supposed to appear _only_ when name1 is different from name2
</c:when>
Mr. Shiny and New 安宇
  • 13,822
  • 6
  • 44
  • 64
  • yes, i tried this, and it has the same result. I changed it to c:If and now it worked. But i did not understand why it did not work with c:When... – Moon13 Feb 12 '10 at 20:28
0

I have noticed some flakiness when using c:if or c:choose and c:when inside some jsf iteration components, such as rich:datatable. What is the full context?

As a workaround, I would commonly have to wrap things in an a4j:outputPanel and set the rendered attribute accordingly.

GreenieMeanie
  • 3,560
  • 4
  • 34
  • 39
-1

Try this...

<c:if test="${bean.name1 ne bean.name2}">
     fields that are supposed to appear _only_ when name1 is different from name2
</c:if>

ne = not equal

Also

# should be $

curv
  • 3,796
  • 4
  • 33
  • 48
-1

Should it be fields that are supposed to appear only when name1 is different from name2

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
  • yes, the fields should appear only when they are different. The problem is that even if they have the same values, it enters the statement, but it was not supposed to. – Moon13 Feb 12 '10 at 20:20
  • I also tried to do this but it is the same result. – Moon13 Feb 12 '10 at 20:21