This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes problem with Map backed ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem with Map backed ActionForm" Watch "problem with Map backed ActionForm" New topic
Author

problem with Map backed ActionForm

Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
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!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
That was quick!

Thanks very much for the advice - I hadn't considered using anything other than simple properties in the Actionform.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with Map backed ActionForm
 
Similar Threads
Mapbacked forms
Topic: finding selected record of nested:iterate using nested:form
Validation of indexed properties
Topic: finding selected record of nested:iterate using nested:form
finding selected record of nested:iterate using nested:form