Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL evaluation clarification

 
Chetan Raju
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,

I require a clarification on EL expressions. Taking examples of EL expressions as below

Case 1
------
a. myMap["mapKey"]
b. myMap[mapKey]

Case 2
------
a. myList["1"]
b. myList[1]

In Case 1 (a) above for a Map, the container does not evaluate "mapKey" but searches the map for a key similar to "mapKey".

In Case 1 (b) above, the container evaluates the mapKey. The container tries to find an attribute named mapKey and substitutes the value of this attribute in the EL expression and then correspondingly finds the key in the Map.

However, in Case 2(both a and b) above for a List, the container finds the item at the specified index in both cases whether index is specified as String literal ["1"] or otherwise [1].

Just want to know whether my understanding is right. If it is, then why is it that in Case 1 and Case 2 are handled differently i.e., the container doesn't evaluate the thing in the braces [] for Case 2 ?

Appreciate your clarification on this.
Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ust want to know whether my understanding is right. If it is, then why is it that in Case 1 and Case 2 are handled differently i.e., the container doesn't evaluate the thing in the braces [] for Case 2 ?

It also evaluates "the thing" in braces, and coerces it into an int.
So,
a. myList["1"]
b. myList[1]
c. mylist[index] is also correct if index refers to an integer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic