• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding EL operators

 
Jyothi Pathuri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I was trying to execute ${"aaa" + 4} and the output is a exception saying "an exception occured while trying to convert "aaa" to type "java.lang.Long" .

EL expressions take any unknown value as 0 in arithmetic expressions and false in relational expressions. This is what I understood. Please correct me if i am wrong. and clarify me the rules of EL operator evaluation .

Regards,
Jyothi
 
Matthew Harkonen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "unknown value" must be an unquoted string. If it is unquoted, it is treated as an attribute or implicit object, and if there is no attribute/object with that name it will be evaluated (in this arithmetical context) to 0. When the string is quoted and doesn't contain a number (such as "1"), the compiler doesn't know how to deal with it and throws an error. Quoted numbers are converted to primitives.

So...

${aaa + 4} // results with 4
${"aaa" + 4} // error
${"4" + 4} // 8
 
Jyothi Pathuri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u Matthew.Now I got the point in arithmetic expressions. if we are using relational operators then what will be the difference.
I have tried to execute the following
${"2" le a }
${"apple" le a }

I got the output false for both the cases . Please explain me how the operators work in relational operators.

Thanks,
Jyothi
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain me how the operators work in relational operators.

Try searching the forum; in particular:

http://www.coderanch.com/t/171963/java-Web-Component-SCWCD/certification/EL-Relational-Operators
 
Vivek Kinra
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles,

Thanks... link you provided was very informative...

I have a small confusion about these three cases

3: ${true > false} <br>
4: ${true > "false"} <br>
6: ${false < "naren"} <br>

"false" evaluates to false so 3 & 4 are of same type and in 6th one "naren" will be converted to false and the expression ${false < "naren"} will become ${false < false}

According to me all these three should be false but they are true...Any ideas???

Thanks...
 
Vivek Kinra
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas/suggestions about the boolean values in EL mentioned in my previous post.

Thanks...
 
Paul Clapham
Sheriff
Posts: 21566
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What it says in my reference to the EL (in appendix A.3.1) is this:

"Comparisons may be made against other values, or against boolean (for equality comparisons only)."

So to me that says that comparing boolean1 < boolean2 is undefined. Does your reference say something different? Mine's the April 2002 version.
 
Vivek Kinra
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul... You are right....

We can use ==,!=,eq,ne for boolean comparision but the result of using other operators(<,<=, lt etc....) is undefined in a expression like
(true < false)...

Thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic