Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

help treating several input boxes as an array

I want to ask the user to input a maximum of 5 contract dates in jsp. Btw, im using struts.

As of now, my code is something like this:


<tr><html:text  property="date1"/></tr>
<tr><html:text  property="date2"/></tr>
<tr><html:text  property="date3"/></tr>
<tr><html:text  property="date4"/></tr>
<tr><html:text  property="date5"/></tr>

<action form>
public class contractForm extends ActionForm {
private String date1;
private String date2;
private String date3;
private String date4;
private String date5;

/* getter and setter for date1 to date5 */

<action servlet>
/* here I have a collection that checks if a date exists then adds it */

Its very tedious, is there a way to do something like

date[0]... date[4] in the <html:text>

then treat it as an array of String in action form?

how do I write the getter and setter in the action form? and how do I retrieve the data in the action servlet?

Can someone provide me with the code for this? Im confused. I'm thinking of using logic:iterate but im not even sure if this is the correct way to implement it.


  • 2
1 Solution
try using the same property name for all fields.
And have a getter/setter that takes an array of strings.
delphiusrAuthor Commented:
Thanks! it worked nicely!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now