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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text boxes array to STRUTS Java Bean Form

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
 
There seem to be rather a lot of misplaced posts here. Is it possible that the java forums are too fragmented, or delineated by irrelevant criteria?

After all, it's all java, and notwithstanding that it's now about 10 times the size of the Windows stuff it originally aimed to replace with a simple, elegant language, the various components do actually fit together quite well.

Perhaps if there were just one java forum, it wouldn't be mis-posted to so often.

I hope this is the correct place to make this suggestion.
 
I guess the division jdk/ j2ee is quite useful, and merging them together wouldn't be very useful. It would help a few beginners but disturb the more concentrated or regular visitors.
It woulnd't solve the problem of javascript-questions too.

To the original question:
Code:
private String[] quantity;
// a setter which returns something?
public String[] setQuantity(String[] quantity)
{
// missing semicolon, missing return statement.
            quantity = quantity
}

// last time, quantity was seen, it was an String [], 
// not just an String.
public String getQuantity()
{
        return quantity;
}

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top