In order to accomplish this in one of my forms I had to implement
ParameterAware (gives me all of the parameters and their values).  This
turned out to be the simplest way for me to deal with this dynamic
functionality.  Also, remember that if you want ParameterAware to work
you need the ServletConfigInterceptor for that action.

LES


-----Original Message-----
From: Alexandru Roman [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 09, 2004 10:01 AM
To: [EMAIL PROTECTED]
Subject: [OS-webwork] dynamic form submission

If I am generating a dynamic row based form, how can I submit the form
elements to the action in a structured manner.

I know it is possible to submit form elements as a collection by giving
the fields the same name as in:
(the same would work for multi select checkboxes)

<INPUT type="textbox" name="addField" value="field value1">
<INPUT type="textbox" name="addField" value="field value2">
<INPUT type="textbox" name="addField" value="field value3">

I would like to take it one step furthur and be able to submit data as
a table with an arbitrary number of rows.

A collection of hashes would be good way. For example:

<INPUT type="textbox" name="row[0]{field1}" value="row 1 field
value1">
<INPUT type="textbox" name="row[0]{field2}" value="row 1 field
value2">
<INPUT type="textbox" name="row[0]{field3}" value="row 1 field
value3">

<INPUT type="textbox" name="row[1]{field1}" value="row 2 field
value1">
<INPUT type="textbox" name="row[1]{field2}" value="row 2 field
value2">
<INPUT type="textbox" name="row[1]{field3}" value="row 3 field
value3">

...


So the action would have a setter for rows:

public void setRows(Collection row) {

  //print out the rows
  Iterator it = row.iterator();
  while(it.hasNext()) {
    HashMap rowData = (HashMap)it.next();
    System.out.println(rowData.get("field1"));
    System.out.println(rowData.get("field2"));
    System.out.println(rowData.get("field3"));
  }

Even better would be to map it directly to a value object for the row
if possible

public void setRows(Collection row) {

  //print out the rows
  Iterator it = row.iterator();
  while(it.hasNext()) {
    Row rowData = (Row)it.next();
    System.out.println(rowData.getField1());
    System.out.println(rowData.getField2());
    System.out.println(rowData.getField3());
  }

So in essence webworks could parse the form element name as
"ObjectName[ObjectIndex]{FieldName}".

thanks,

Alex.


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to