• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Iterating a hashmap in jsp using struts2

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Google it!
HashMaps i think by using an iterator and .key and .value property ! With OGNL expressions i think.!Not too hard
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic