• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to work out 2 dimensional arrayLists  RSS feed

 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a collection of objects called 'folders' and another one called 'metal'. Basically the idea is each folder has a specific metal attached to it. So I though about the best way to implement this without violating any object oriented principles:

basically what i did is this:




when I try to show this on my jsp page, I do the following:





And i get the appropriate output.

The thing is, I don't like this way!! It seems wrong and inflexible. Parallel arrays are a thing of the past.

Is there a better way to implement this?

Thanks,
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayLists and JSTL's forEach tags can both be nested.

See: http://faq.javaranch.com/java/JstlTable
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but how will that help with problem I've got? I have two different objects. I may put them in a map for example, but Maps aren't designed for this. What if I have three objects in parallel?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I meant was one map or list to represent each row.
If you want something more specific, you could create a bean with explicit properties for each column.


Using a map, it would look something like this:



This way, the relationships are all worked out before you pass context to the JSP



With one collection per row, you could add as many columns as you like, without having to resort to parallel lists or arrays.

Does that help?
[ January 21, 2008: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!