views:

270

answers:

6

Hi,

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

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 $

zinc
Hi, i tried with $ but it does work. i had to change to the C:IF tag. Thanks.
Moon13
cool ok, just realised it should be c:if too - i didn't understand your original question
zinc
A: 

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

fastcodejava
yes, the fields should appear only when they are different. The problem is that even if they have the same values, it enters the <c:when> statement, but it was not supposed to.
Moon13
I also tried to do this <c:when test="#{not (bean.name1 eq bean.name2) }"> but it is the same result.
Moon13
+1  A: 

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
Not if its wrapped in a <c:choose> tag
John V.
yes! Why C:when does not work???
Moon13
# should be $...
zinc
# is also valid if using facelets.
GreenieMeanie
Why the downvote?
fastcodejava
A: 

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
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
+3  A: 

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 V.
yeah, you are right! :) i forgot the <c:choose> tag. haha.
Moon13
thanks a lot! :D
Moon13
No problem glad to help!
John V.
A: 

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