| Author |
<c:set target>
|
Moses Marfo
Greenhorn
Joined: May 24, 2009
Posts: 26
|
|
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
Joined: Apr 21, 2008
Posts: 432
|
|
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
Joined: May 24, 2009
Posts: 26
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Moses Marfo
Greenhorn
Joined: May 24, 2009
Posts: 26
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
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
Joined: Oct 26, 2008
Posts: 119
|
|
Hello Ankit,
Nice explanation!!
when i read this statement in HFSJ , i did not fully get it .
but now
|
SCJP 5 , SCWCD 5
|
 |
Moses Marfo
Greenhorn
Joined: May 24, 2009
Posts: 26
|
|
Ankit,
O.k I get it now thanks.
|
 |
 |
|
|
subject: <c:set target>
|
|
|