我正在尝试比较 JSF 中的两个不同对象。 一个字符串和一个整数,当然不行...
//myVar ==> 整数对象
//myVar2 ==> 字符串
<c:if test="${myVar == myVar2}">
YES!!!!!!!!
</c:if>
我尝试使用 myVar.toString 但它是错误的。 那怎么办呢?
谢谢
最佳答案
I'm trying to compare two different object in JSF. A String and an Integer, of cours it don't work...
这听起来不对 - 我会检查这些值。对于 bean :
public class CoercedBean {
public int getValueAsInt() {
return 123;
}
public String getValueAsString() {
return "123";
}
}
...这些示例表达式的计算结果为 true:
${coercedBean.valueAsInt == coercedBean.valueAsString}
<h:outputText style="color: blue"
value="#{coercedBean.valueAsInt eq coercedBean.valueAsString}" />
JSP 2.1 (EL) 规范说明了评估相等性:
A {==,!=,eq,ne} B
If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to Long, apply operator
关于JSF <c :if> with different object type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/965910/