简体   繁体   English

如何在EL中比较String变量?

[英]How to compare String variables in EL?

I have a bean Mybean with 2 properties: 我有一个具有2个属性的bean Mybean

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

I need to display stringArr in a <t:dataList> as follows: 我需要在<t:dataList>显示stringArr ,如下所示:

<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? 如何在每次迭代中在test="#{???}"中将#{user.name}与var #{i}进行比较? I ultimately need to check if user.name == i . 我最终需要检查user.name == i

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 : 如果我没看错您的问题,您想根据循环变量的状态输出某些内容,例如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. 如果条件为真,则将打印match否则为no match

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM