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


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 forms and collections" Watch "Struts 2 forms and collections" New topic
Author

Struts 2 forms and collections

Glenn Puckett
Greenhorn

Joined: Sep 09, 2008
Posts: 16
I have recently made the move from Struts 1 to Struts 2 and am really glad I made the move. With one exception. For some reason I really have a tough problem coding my JSP code to properly access data from my action module. It is improving but I find using collections a total mistery. I have a page I am trying to get working where a Collection is the only practical answer. There are a variable number of entries that should appear on a form, give the user the opportunity to change a column of numbers then submit the data for update to an sql table.

I have tried coding this several different ways using HashMaps, ArrayLists and arrays and so far have not got it working properly. I can get the current data to display on the form but no data ever returns back to the action module.

I have set up a small bean that holds each instance of the data:



In the action class I build an ArrayList of these beans with data from an SQL table. Also I have appropriate getter and setter in the action class for the ArrayList object.



In my jsp/Struts 2 code I build a form and populate it using an iterator.




When I bring up the form and look at the html source it contains what appears to me to be accurate coding. Here is a small example:




When I make changes and then submit the form the ArrayList has the correct number of entries. But they are all null. In another combination using HashMap I was able to get the date back properly but the headCount field was null. In another case the headCount field had an OGNL error message in it.

I have tried using a simple HashMap with the date as the key and a Double for the count (nulls in count). I have tried TreeMap using date for sequence and then CraftLaborPeriodDetail as the value (nulls for value). So I am missing something very basic when it comes to getting data BACK INTO the collection following a submit. ALSO, I tried changing the double to a String just to see what would happen and nothing changed. It still came back as a null.

Please help. I am getting desparate to get this module completed so I can make progress on my development.
Glenn Puckett
Greenhorn

Joined: Sep 09, 2008
Posts: 16
Wow.. Thanks for the overwhelming response!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 forms and collections