File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes setting hashmap value using jstl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "setting hashmap value using jstl" Watch "setting hashmap value using jstl" New topic
Author

setting hashmap value using jstl

Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
Hi,

I have a structure like this...
list -> hashmap

Now I am able to display hashmap values in different textboxes using JSTL but I want to have my original hashmap values also.

Here is how I am displaying my original hashmap.
<c:forEach items="${List[1].termAmtMap}" var="th2Obj">
<html:text property="${th2Obj.key}" value="${th2Obj.value}" size="7"/>%
(<c:out value="${th2Obj.key}" /> Y)
</c:forEach>

Now I am tring to keep original values also using <c:set> but it is not workin, it says classcastexception and that is becauase Key is integer while value I am setting is String.
<c:set target="oriList[1].termAmtMap" property = "oriList[1].termAmtMap.key" value="${List[1].termAmtMap.key}"></c:set>

Please help with this issue.Thanks in advance.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
My advice: don't do this in JSTL, do it in java code.
JSTL is great for displaying contents of maps.
It is not particularly useful with manipulating maps.

Said java code should of course reside in a servlet/bean, not on the JSP page.

Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
thanks stephan for reply.

I agree completely with your point, but my problem is this is exising application in struts1.2 and I am now allowed to change any existing implementation :-(
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Look at the docs for <c:set>. Particularly the target and property attributes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: setting hashmap value using jstl
 
Similar Threads
Using JSTL and Struts
struts dynavalidatorBean with HashMap & JSTL
How to Set HashMap in request attribute using JSTL Tag
Setting an object with c:set from sessionScope
Problem with setting values in hashmap in struts