开发者

Comparing strings with JSTL

I have two strings that i need to compare, but even 开发者_Go百科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>


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


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.


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>


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.


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


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 $

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜