• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL question

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are the different combinations:



Hope it helps
 
Stella Kim
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are right Ali,
I tried and it does print "new"..
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic