• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question regarding looping

 
Eric Sexton
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • 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?
 
Angel Dobbs-Sciortino
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Struts and Other Frameworks forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic