Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About the "target" attribute of c:set

 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In page 446 of HFSJ, it says that the "target" is not for the attribute name of the bean or map, but for the actual attribute object.

I am not sure what it really means, because in page 486 Q4, the "target" is used as an attribute name without any problem.
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what exactly it means it in <c:set> tag target is used to set the value of map or bean. so the target value should be the actual object..
Le me explain with example how target should be used...
<% Map map = createMap();%>
<c:set target="<%=map%>" ....>
the value of target should evaluate to actual map object..

You should not use that in the following way...
<%
// This can very well go into servlet also.
Map map = createMap();
request.setAttribute("map", map);
%>
<c:set target="map" ...../>
this is wrong.. because target is evaluating to string or attribute name and it is not evaluating to actual map..
bottom line, is always you need to assign target value using expression.
Hope, I made sense.

Originally posted by Edmund Yong:
In page 446 of HFSJ, it says that the "target" is not for the attribute name of the bean or map, but for the actual attribute object.

I am not sure what it really means, because in page 486 Q4, the "target" is used as an attribute name without any problem.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not use that in the following way...
<%
// This can very well go into servlet also.
Map map = createMap();
request.setAttribute("map", map);
%>
<c:set target="map" ...../>
this is wrong.. because target is evaluating to string or attribute name and it is not evaluating to actual map..
bottom line, is always you need to assign target value using expression.

What's wrong with that? In Q4 of the chapter, it's doing this way, isn't it?

So I can do (assuming that there is a key called "key", and you want to set a value called "val"):

<c:set target="requestScope.map" property="key" value="val" />
 
M Rama
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What's wrong with that? In Q4 of the chapter, it's doing this way, isn't it?

So I can do (assuming that there is a key called "key", and you want to set a value called "val"):

<c:set target="requestScope.map" property="key" value="val" />


I think the code should be:



instead which will be the EL for the the object.That is what the Q4 in the same chapter does.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think, it should be

<c:set target="${requestScope.map}" property="key" value="val" />

or

<c:set target="${map}" property="key" value="val" />


Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic