• 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

Struts Iterator best Object usage

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all I am now getting a bit more comfortable with the iterator in Struts, and it's time for me to design some structures to store my data in.

I want to be able to put multiple strings and iterate over parts of each of the string sets.
So for example if I have productName, productDesc and productPrice, I was thinking of storing these things in an object, and them putting all of these objects in a data structure (this is the part that I am curious about what would make the best sense). When I stated that I want to iterate over parts of the list I was thinking that I could use the length and the offset values in the iterate function to implement paging. Does this seem reasonable, and can what I want to do with respect to the collection of objects work with the iterator ?

Hopefully that made enough sense if not please let me know and i'll try to explain it more clearly.

Cheers
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recommended datastructure: Plain vanilla java.util.List (probably ArrayList)

Alternatively if you are going to be looking up the products by id, storing them in a Map (hashmap) keyed by id is a good way to go. With struts you will probably have to make sure that the "key" values are Strings, not Integer objects.
 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using array list, but the part that has me a little confused is how I am supposed to iterate through all of the values at the same time. Suppose I have elements 1,2 and 3. I then place those into an object and then put the object into the array. the part that I am confused on is how does one pull out the individual components from the object- can a method call be used ?

thanks once again.

The other thought that came to mind was maintaining multiple Arraylists but that just seemed too ugly to work with.
[ September 19, 2006: Message edited by: A knibbs ]
 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems that all I had to do was to make accessors for all the variables and then just add them in. I am quite impressed by how simple it actually was. I am enjoying struts more and more as I learn it.
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic