• 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

Iterating over a list object to populate a 2D array

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings,

I am attempting to gather user input from a web page using a table. Per the kind reply to my previous post, I am using JSTL to iterate over a couple of lists and retrieving the information from an array of input tags on the page. The information is being successfully written, to a string array attribute, which is defined in my bean.

It was suggested previously that I iterate over a List<Object>. I would prefer to do this, and populate a 2D array of strings in my bean, rather than returning one long one dimensional array which is currently the case. Would anyone be able to suggest how I might structure my c:forEach loops to accomplish this? Thank you.

Here is the bean code:



Table records are built from a list of strings:



Here is the jsp (with JSTL!). This is what I would like to rewrite to populate a 2D array.



The bean property inputFields is registered in the jsp page and is updated when the page is submitted. The next
page gets the array from the bean:



Thanks again.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with the nested forEach tags that you have now?

P.S. posTblRecords? This is not Wheel of Fortune and vowels do not cost $250 each. Why freeze-dry names? Sorry -- personal pet peeve of mine.
 
Jerry Goldsmith
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. The nested tags that I have now return a one dimensional array. There is no way to determine what row of the table the array elements originally belonged to. I want to write the records to the bean and, eventually, back to the database table they came from.

With a 2D array the first index would be the row number (i.e. the outer loop) and the second index would be the column number (i.e. the inner loop). All I'm really looking to do is display a table of data on a web page, that a user can edit, and read the table back into my bean. There is probably a better approach that I am unaware of.

Freeze dried names? How about:



Sorry. I'm getting a little bit punchy.
reply
    Bookmark Topic Watch Topic
  • New Topic