Hi all,
There's a form in a struts based web-application in which some fields will be made according to some varable parameters. I mean number of those text type fields may vary from 2 to 100.
Any idea for building ActionForm class such that fields of that formBean be set automatically (obviously after the form submitted)?
Thanks
Majid Makki
-
Struts and Dynamic Fields of a Form (5 messages)
- Posted by: Majid Makki
- Posted on: July 10 2004 06:06 EDT
Threaded Messages (5)
- Struts and Dynamic Fields of a Form by Senthil Chinnaiyan on July 10 2004 09:03 EDT
- Struts and Dynamic Fields of a Form by Majid Makki on July 10 2004 09:51 EDT
- Struts and Dynamic Fields of a Form by Senthil Chinnaiyan on July 10 2004 10:37 EDT
- Struts and Dynamic Fields of a Form by Majid Makki on July 10 2004 09:51 EDT
- DynaActionForms by jason priestly on July 10 2004 13:11 EDT
- Re: Dynamic Forms by Lisa Pedrazzi on August 01 2007 02:32 EDT
-
Struts and Dynamic Fields of a Form[ Go to top ]
- Posted by: Senthil Chinnaiyan
- Posted on: July 10 2004 09:03 EDT
- in response to Majid Makki
Have the attribute type as String[] in form class and use that attribute in the jsp, when you submit all the posted values will be assigned in your array attribute.
Hope this helps,
Senthil. -
Struts and Dynamic Fields of a Form[ Go to top ]
- Posted by: Majid Makki
- Posted on: July 10 2004 09:51 EDT
- in response to Senthil Chinnaiyan
And what about relation between name of the text field in JSP and name of the String[] in the form class. I mean how they will be mapped?
I think an example can make it clear for me.
Thanks again
Majid Makki -
Struts and Dynamic Fields of a Form[ Go to top ]
- Posted by: Senthil Chinnaiyan
- Posted on: July 10 2004 10:37 EDT
- in response to Majid Makki
Basically if you have a same variable name and multiple values, http will send all values as name & value pairs. Struts will present those as String[] in your form class.
For Example:
<input type="text" name="varName" value="aaa" >
<input type="text" name="varName" value="bbb" >
<input type="text" name="varName" value="ccc" >
In http,these values will be sent as varName=aaa&varName=bbb&varName=ccc. In your form class if you have a variable it will be populated.
class MyForm extends ..... {
private String varName[];
public String[] getVarName() {}
public void setVarName(String[] varName) {
this.varName = varName;
}
}
Here the getVarName() will return all values of the variable varName.
Hope this helps,
Senthil. -
DynaActionForms[ Go to top ]
- Posted by: jason priestly
- Posted on: July 10 2004 13:11 EDT
- in response to Majid Makki
You could use DynaActionForms
http://www.reumann.net/do/struts/lesson3/step4
http://www.developer.com/java/web/article.php/2214681 -
Re: Dynamic Forms[ Go to top ]
- Posted by: Lisa Pedrazzi
- Posted on: August 01 2007 02:32 EDT
- in response to jason priestly
I'm sorry in bothering you, but I'm new to Struts and I'm having this problem for many days without found any working solution (for me). I have Struts 1.1 (sigh, I must use this version) and I'm trying to get some multiple/dynamic file from a form (file's number depends on a field specified by users) as posted. When I reach the page all goes well, I can put the number of the file I want to upload, I can select the file but... when I press the submit botton I get an exception. Here is my code. The jsp page: 0){ for(int i=0; i<numSubreport; i++){ String propertyName = "file"; //String propertyName = "file["+i+"]"; %> : The bean for the form has this getter setter method (plus other for get/set other params) public int getNumFile() { return numFile; } public void setNumFile(int numFile) { this.numFile = numFile; file = new FormFile[this.numFile]; for(int i=0; i<this.numFile; i++){ file[i]=null; } } public FormFile[] getFile() { return file; } public void setFile(FormFile[] formFile) { file=formFile; } The Exception I get: javax.servlet.ServletException: BeanUtils.populate at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203) ... I found a similar problem also in ASF's bugzilla. It was marked as a non-bug (I have no doubt in this). If can help the id is 13075. Thanks in advance, Lisa