Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of Text Boxes to Java Bean Struts

Status
Not open for further replies.

alexander1113

Programmer
Dec 26, 2004
26
US
Hello all,
I am utilizing the MVC architecture via Struts. I have a page which prints out a dynamic list of text boxes and are printed as follows:

<input type="text" name="MyForm.quantity[0]" value="2"/>
<input type="text" name="MyForm.quantity[1]" value="2"/>
<input type="text" name="MyForm.quantity[2]" value="2"/>
.... COULD BE MORE TEXT BOXES COULD BE LESS...

These text boxes are all in one form. Now when there is a submit it gets set to a bean which I have created like this:

private String[] quantity;
public String[] setQuantity(String[] quantity)
{
quantity = quantity
}
public String getQuantity()
{
return quantity;
}

But I am getting null when in the action I do:

action..blah blah blah
MyForm myform = (MyForm)form
//getting my bean from the jsp form

System.out.println(myform.getQuantity());

Can anyone help. If you need more information please post, I need to get this solved and have been racking my brain.

Alex
 
NM I finally Figured it out. It's a patch but it works. ANyone has another better solution, please by all means, post it.

private String[] quantity;
public String[] setQuantity(String[] quantity)
{
quantity = quantity
}
public String getQuantity()
{
return quantity;
}

should be:

private String[] quantity = new String[1000];
public String[] setQuantity(String[] quantity)
{
quantity = quantity
}
public String getQuantity()
{
return quantity;
}

I made a fixed length, because i know for a fact that it will never surpass 1000 items.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top