Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<c:set target>

 
Moses Marfo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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)...
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ankit,
O.k I get it now thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic