This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes question regarding looping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "question regarding looping" Watch "question regarding looping" New topic
Author

question regarding looping

Eric Sexton
Ranch Hand

Joined: Sep 12, 2003
Posts: 133
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

Joined: Sep 10, 2003
Posts: 101
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

Joined: Sep 12, 2003
Posts: 133
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

Joined: Sep 10, 2003
Posts: 101
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

Joined: Oct 29, 2001
Posts: 8842
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Struts and Other Frameworks forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question regarding looping
 
Similar Threads
Dispatch[/ActionName ] to method method1 returned an exception
Request Parameters in EL
Problem with whitespace in form
null value in request
mapping.getAttribute gives null pointer exception