GeeCON Prague 2014*
The moose likes Struts and the fly likes Struts - Variable # of TextField in Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts - Variable # of TextField in Form" Watch "Struts - Variable # of TextField in Form" New topic
Author

Struts - Variable # of TextField in Form

ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi All
The business requirement on the project which I am currently working on is such that until runtime I don't know that exact # of TextField in JSP page. The Struts requirement is such that you need to declare a attribute in formbean corresponding to each form field in JSP. How can we take care of this requirement of variable number of a form field say TextField in JSP page.
I am thinking of a solution in terms of declaring all the TextField in JSP with the same name say 'textfield' and corresponding attribute in the form bean as String[] textfield ? Is it a limitation in Struts that we can't have variable number of form fields in a JSP or it is already taken care of latest version of Struts. I have gone thorugh the Struts user guide but nowhere I find sufficent documentation which address this particular situation.
Thanks in advance
Ravindra


SCJP, SCJD, SCWCD, SCBCD, SCEA
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
You can use a Map based ActionForm that has two methods:
public void setValue( String key , Object value )
public Object getValue( String key )
You html:text tag would look like this:
<html:text property="value(key)"/>
I hope that helps.


Matthew Phillips
ravi janap
Ranch Hand

Joined: Nov 04, 2000
Posts: 389
Hi Mathew
What do you mean by Map based ActionForm ?
Do I need to declare a attribute in the formbean of data-type Map. If Yes, What does this attribute signify ? How does it maps to the text field on JSP ?
Thanks
Ravindra
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Do I need to declare a attribute in the formbean of data-type Map.

Yes. And you use the access methods I mentioned in my previous post.
If Yes, What does this attribute signify ?

It is a Map of the fields you include in it. Instead of your tags writing to a specific property they write to a generic Map as key/value pairs.
How does it maps to the text field on JSP ?

See my previous post for an example.
 
GeeCON Prague 2014
 
subject: Struts - Variable # of TextField in Form