• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Struts - Variable # of TextField in Form

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic