Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF <c:if> with different object type

I'm trying to compare two different object in JSF. A String and an Integer, of cours it don't work...

//myVar ==> Integer object
//myVar2 ==> String

<c:if test="${myVar == myVar2}">
    YES!!!!!!!!
</c:if>

I try with myVar.toString but it's wrong. So how to do it ?

Thank's

like image 728
Martin Magakian Avatar asked Feb 03 '26 04:02

Martin Magakian


1 Answers

I'm trying to compare two different object in JSF. A String and an Integer, of cours it don't work...

That does not sound right - I would check the values. For the bean:

public class CoercedBean {

  public int getValueAsInt() {
    return 123;
  }

  public String getValueAsString() {
    return "123";
  }

}

...these example expressions evaluate to true:

${coercedBean.valueAsInt == coercedBean.valueAsString}
<h:outputText style="color: blue"
    value="#{coercedBean.valueAsInt eq coercedBean.valueAsString}" />

The JSP 2.1 (EL) spec says of evaluating equality:

A {==,!=,eq,ne} B

If A or B is Byte, Short, Character, Integer, or Long coerce both A and B to Long, apply operator

like image 57
McDowell Avatar answered Feb 04 '26 23:02

McDowell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!