• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL question

 
Stella Kim
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say :

java.util.Map myMap = new java.util.HashMap( );
myMap.put("a", "b");
myMap.put("b", "c");
myMap.put("c", "d");
setAttribute("myMap", myMap);

setAttribute("b", "c");
____________________________________________________

${myMap[b]} ---- prints d (as I expected)
${requestScope[b]} ---- prints nothing ...why?
Anyone can explain the underlying process about this?
(requestScope is just another map with key and value, then why
requestScope[b] cannot find the attribute value bound to b, which is "c" here)

[ January 24, 2007: Message edited by: Stella Kim ]
[ January 24, 2007: Message edited by: Stella Kim ]
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the different combinations:



Hope it helps
 
Stella Kim
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ali,
I know it needs quotes in ${requestScope['b']} like this.

But, I was just curios what will happen if I don't put quotes inside the brackets with EL implicit object
and I thought it might try to the attribute bound under that name and substitue tha value of that attribute,
as it does in ${myMap[b]}.
[ January 24, 2007: Message edited by: Stella Kim ]
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, I was just curios what will happen if I don't put quotes inside the brackets with EL implicit object
and I thought it might try to the attribute bound under that name and substitue tha value of that attribute,
as it does in ${myMap[b]}.


yes...it should work....they way you are curious...
but why didnt it work..

didnt get ali

:roll:
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its straightforward, let me explain

In case of myMap[b], the EL will substitute the value of b by finding it in request scope and it will turn out to myMap['c']

whereas in case of requestScope[b] it will turn out to be requestScope['c'] and there isn't anything available in request scope map with key 'c'.

you can try it by adding request.setAttribute("c","new"). Now it will print new.

Hope it clarifies your doubts
 
Stella Kim
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right Ali,
I tried and it does print "new"..
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic