• 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

question regarding looping

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have that looks like this:

In my servlet, there is an attribute that I can check to see how many SSNs are submitted in the form. What I want to do is build som type of looping logic to cycle through these. In other words I want this effect:

So I want to avoid typing out each of the preceding lines because I can potentially have 30 SSNs submitted on the form. What's the cleanest way to do this?
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:

Angel
[ November 26, 2003: Message edited by: Angel Dobbs-Sciortino ]
[ November 26, 2003: Message edited by: Angel Dobbs-Sciortino ]
 
Eric Sexton
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each of those getSsnX methods actually correspond to a form bean in Jakarta Struts. So this dynamic form could potentially have 30 text boxes on a screen that each have an Ssn in them. Not all the fields are required either. So even though 30 Ssns may be on the form, the user can choose to simply enter in 1 Ssn.
 
Angel Dobbs-Sciortino
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public String[] getAllSsn() in PersonForm could just call each of the getSsnx methods and return an array of all the Ssn's that were actually entered.
Angel
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at how to use Indexed Properties in the Struts documentation. You can use arrays or Lists to represent groups of data rather than having 30 member variables and 60 accessor methods.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Struts and Other Frameworks forum...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic