wood burning stoves
The moose likes Struts and the fly likes Arrays in JSP form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Arrays in JSP form" Watch "Arrays in JSP form" New topic

Arrays in JSP form

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179

I am looking for the best solution to my problem and I describe it with a small example.

I have a ArrayList of products:

And that ArrayList of products is sent to a form, where user can review the product list and change the quantity of each individual product. After submitting it, servlet takes over then.

Now the question is: how to construct that form, so that it is comfortable to access the data from servlet?

Here is one solution:

And in this case it is not so easy to get the parameters in servlet. When the data is like so:
id_1=2; price_1=200; quantity_1=3;
id_2=16; price_2=300; quantity_2=1;
id_3=7; price_3=50; quantity_3=5;
So in servlet I have to check when the ${loopCount.count} stopped by compareing if request.getParameter("id_3")==null

But I am woundering, if there is more better solution for that type of problem. In my mind I am thinking of presenting and getting back arrays from html form somehow, but I don't know if it is possible.

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
And another thing (even though it gous to struts subject): how to make a ActionForm to validate this generated form, because I don't know how many "quantity_x" parameters there will be?
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
Yes there is a better way.
Struts "indexed properties"

I agree. Here's the link: http://aspose.com/file-tools
subject: Arrays in JSP form
It's not a secret anymore!