• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with Map backed ActionForm

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a fairly simple JavaBean class to represent a business object. I also have an ActionForm which needs to hold the values for several of these beans, and I've decided to use a series of Maps to hold the properties in the ActionForm. The Map key is a String property from the business object.

For example, I need to present properties from several Students on a single form. So I have:



In the JSP I have:



The ActionForm and JSP work, I just can't find a good way to reconstruct the set of students using BeanUtils or PropertyUtils in the target action when the form is submitted. At present I have all sorts of loops etc, and copying out the properties individually.

Please tell me I'm missing something and there's a MUCH better way of doing it!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Please tell me I'm missing something and there's a MUCH better way of doing it!



Ok, you asked for it. Get rid of all the HashMaps. I assume you've already created a Student object that contains all the properties (age, gender, surname,etc.). Fine. Keep that and create a property on your ActionForm bean named "students" of type java.util.List. This property will contain an ArrayList of all the Student objects you wish to work with on the form. Then use "indexed properties" to access each student. This link will give you some good pointers on using indexed properties.

Then in your Action class, all you have to do is iterate through the List of Student objects to get the updated properties for each Student.
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was quick!

Thanks very much for the advice - I hadn't considered using anything other than simple properties in the Actionform.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic