Win a copy of Design for the Mind this week in the Design forum!

# Valid operands in a EL expression?

Veena Pointi
Ranch Hand
Posts: 442
When we use arithmetic/logical/Relational operators in EL,what are valid operands we can use? On page 393 of HFSJ it was given

\${num>2}
\${integer le 12}

where num and integer were String and Integer type respectively ! stringType>2 throws error in java.How to know what types are valid and what types are not valid for operands in EL?

Thanks
Veena
[ April 06, 2006: Message edited by: Veena Point ]

Veena Pointi
Ranch Hand
Posts: 442

Narendra Dhande
Ranch Hand
Posts: 951
Hi,

Before going to the operators we summerize the conversion rules.
Boolean can be converted to only String.
Character Can converted to Number and String.
Number ( number in Wrapper or constants ) can be converted to Character and String.
String can be converted to Number,Characher and Boolean.

Arithmatic Operators.

In general binary operations, the value are coerec to highest type and operatio is performed. The operand first converted to numeric as per conversion rules then the operator is applied. If the operator result in exception, error is thrown. ( e.g. If the String value can not converted to numeric, it is error)

Relational Operators.
Operates on Numeric, String (lexical), and comparable.

Logical Operators
Operates on boolean values. Coerce both operands to Boolean and apply the operator ( only string other than boolean can be converted to boolean).

\${num>2}
\${integer le 12}

In this example you are using numeric constants, so it is numeric comparision. The string value in num will convert into number.In the second example the value of wrapper class is used for comparision.

Thanks
[ April 07, 2006: Message edited by: Narendra Dhande ]

Veena Pointi
Ranch Hand
Posts: 442
Thanks Narendra.You meant converted or casted?conversion rules are applies\d or casting rules?

Narendra Dhande
Ranch Hand
Posts: 951
Hi,

I think it is not casting. The Specification use the word "coerec".

Thanks