• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

<c:set target>

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody please explain why the code below works.
According to HSJP the "taget" must evaluate to the OBJECT, you don't type in the string "id" name of the bean or Map attribute
I thought I had to set the map value like this

instead of this

when using target.

I'm using netbeans as my IDE.


thanks
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Moses.
It should be in this example.
Here '${map}' gets the map object that was set in request scope and finds any key named with 'id', if finds replaces the old value to the new value ('NewValue') and if not finds, then adds the new key 'id' with value 'NewValue'.
 
Moses Marfo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chinmaya,
Are you saying this is an exception to the statement made in HFSJ (the "taget" must evaluate to the OBJECT,) or I must use
'${map}' because it is a request attribute.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as i understand, what you are saying is that in your JSP, the name of your Map is testMap and you are setting it with the name map in the request scope. Now if you want to confirm that whether you have to use ${testMap} or ${map}, then try to write ${testMap.id} and ${map.id} in your JSP somewhere and see if it works. The EL looks into different scopes for attributes that you name. It will not look at any declarations of objects in your scriptlets. See this



So in your case, ${testMap} would not point to any object but ${map} will...
 
Moses Marfo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit
Initially I was trying ${testMap.id} due to the statement ("target" must evaluate to the OBJECT, you don't type in the string "id" name of the bean or Map attribute".) in the HFJS, then I tried ${map.id} and it started to work, from then I got confused based on the statement made in the book.

Thanks for the help. I will be grateful if you can provide an example where "target" must evaluate to the OBJECT when using a Map.

thanks
Moses
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moses, I think you are a little confused here. A Map object is also an Object, what the book meant is that the target expression should not be name of an attribute in a scope, instead you should use EL to point to the exact attribute in any scope. So basically instead of saying the name of the attribute (like myAttr), you use EL to point to the object in a scope (like ${requestScope.myAttr}). Here Object doesn't mean a reference declared in a scriptlet (like testMap reference in your JSP)...
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ankit,
Nice explanation!!

when i read this statement in HFSJ , i did not fully get it .
but now
 
Moses Marfo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankit,
O.k I get it now thanks.
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic