permaculture playing cards*
The moose likes Struts and the fly likes Iterating a hashmap in jsp using struts2 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 » Frameworks » Struts
Bookmark "Iterating a hashmap in jsp using struts2" Watch "Iterating a hashmap in jsp using struts2" New topic
Author

Iterating a hashmap in jsp using struts2

Ankush Sharma
Greenhorn

Joined: Sep 12, 2009
Posts: 3
Hi,

I am trying to create a dynamic form while iterating an arraylist of entity objects.display fields are hashmap values where I should be able to edit the hashmap fields hashmap<String,value an Object) and submit the form values back.I am able to create the dynamic form but when I submit,cant get the values back in my Action class,as Arraylist becomes empty while submitting my form.I am using struts2 in my application

Any better solution for iterating a hashmap and getting the complete hashmap in the Action class.
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
Google it!
HashMaps i think by using an iterator and .key and .value property ! With OGNL expressions i think.!Not too hard
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Hi Ankush, welcome to javaranch.

The problem as I understand is that you want the HashMap to be available to the action that receives the request after you submit the form. Well this will not happen automatically for you. You can put the HashMap into the session and access it in the target Action. BTW what are the values stored in your HashMap, are they objects of a specific class??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How are you declaring the map in the action you're submitting to?

@Ankit: I'm not sure what you're saying; maps can be passed to JSP as an action property, just like simple types, and populated from form submission if the form element names are written using map syntax.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

@David, what I meant was that suppose that if he has a map which contains arbitrary values (as he said that the map is <String,Object>), and he wants the Map to render the JSP and the Next Action to have that map, then he can put it in session so that the next Action can get it out of the session. And if the objects are of a particular type, like lets say Employee, then he can do what you are saying, or implement a custom type converter if for example only the employee's ID is in the form, then the custom Type converter can be used to convert that ID into Employee automatically. That's why I asked what are the objects stored in the HashMap as values. I hope I'm not off the track and I've understood the problem correctly...
 
 
subject: Iterating a hashmap in jsp using struts2
 
Similar Threads
Validation Framework in struts2
Struts2 - Conditional validation
struts2 problem
How to close the session in struts.confiq.xml
Problem populating a newly created HashMap in a Struts2 Action