Ryo
Ryo

Reputation: 1035

How to compare String variables in EL?

I have a bean Mybean with 2 properties:

ArrayList<String> stringArr = {'a','b','c'};
User user; // With 'name' property.

I need to display stringArr in a <t:dataList> as follows:

<t:dataList value="#{MyBean.a}" var="i">
     <!-- Compare user.name bean propery with i. -->
     <c:if test="#{???}"></c:if>
</t:dataList>

How can I in test="#{???}" compare the #{user.name} with var #{i} on every iteration? I ultimately need to check if user.name == i.

Upvotes: 0

Views: 4684

Answers (1)

Matt Handy
Matt Handy

Reputation: 30025

If I don't misread your question you want to output something based on the state of a loop variable, so for instance for an h:outputText:

<t:dataList value="#{MyBean.a}" var="i">
  <h:outputText value="#{MyBean.user.name == i ? 'match' : 'no match'}"/>
</t:dataList>

This will print match if the condition is true and no match if not.

Upvotes: 4

Related Questions