aspose file tools*
The moose likes Struts and the fly likes Arraylist problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Arraylist problem" Watch "Arraylist problem" New topic
Author

Arraylist problem

Terri Layman
Greenhorn

Joined: Nov 03, 2008
Posts: 25
Good Morning (or whatever it may be for you!)

I am trying to add items to an arraylist. I know all about the arrayList.add(). However, the problem I'm running into is that I am using an object to hold the data (its summarization information for a report) of ExpenseItem, and I can't manage to get an arraylist to build properly so that it can be displayed. What I am doing is below:



So, as you can see, I bring in an external array, populate it from the form if data exists in the form, adding data to the array, and then writing it back to the form. It sounds like it should work, but I'm getting some really unexpected results when I do a println off the arrayList. I'm getting something similar to below:



Any ideas on how to make it one consistant arraylist?

Thanks,
-TerriLyn
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ugh; seems like a day object would have made that a little cleaner :(If getWeekInfo() returns a list (which the poorly-named wIc implies) you're adding a list into a list, producing a nested list. You may be thinking of java.util.Collection's addAll(...) method.

Additionally:Besides both comments being redundant, the first comment is also plain wrong and misleading.
Terri Layman
Greenhorn

Joined: Nov 03, 2008
Posts: 25
David,

Thanks for looking at it, but I think I may have sorted it out.

At the point in the code that calls the "storeValues()" I changed how the array is constructed.



At that point it constructs the array that gets passed to the storeValues. It also checks to see if the arraylist in the form is empty, if it's not it overrides the inital construction of the arraylist with the constructor that loads it from the form.

Then in the storeValues(), I'm getting the "Week Info Count" (your referenced badly named wIc). That gives me the position where to add another object (WCI) to the "overall" arraylist. I then set the arraylist in the form to the value of the new "local" arraylist.



Make sense?

Now if I could only get it to STOP re-appending the new data to the arraylist once the summary page is drawn, should the user hit the refresh button or some such, life would be golden, and I'd be down to format clean up.

Thanks for looking!

-Terri
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arraylist problem
 
Similar Threads
scriplet-UI clash issue
shallow copy
outputing an arraylist of arraylists to a file.
Compare two ArrayList
how to compare if object exists in arraylist and add if doesn't