File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arraylist problem

 
Terri Layman
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic