JSF <c :if> with different object type

标签 jsf types jstl compare if-statement

我正在尝试比较 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/

相关文章:

jsf - 我最初如何隐藏 p :dataTable with p:columnToggler 中的列

java - JSF中如何访问动态页面的内容?

java - JSTL:c:forEach 是否保证 JSP 中的列表排序?

java - 如何使用 JSTL <c :set> 存储字符

c - 为什么我不能分配结构参数? (C)

java - 如何遍历 jSTL 中的列表列表?

ajax - jsf 2 primefaces openDialog 不起作用?

java - 如何单击行并使用托管 bean 传递变量

swift - Swift "as"和 "as!"类型转换操作有什么区别?

C 类型声明 intN_t