File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts : Dynamic HTML form parameters

 
Rohit Poddar
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a requirement where the HTML form input paramater names are dynamically generated and hence I cannot have them as property in ActionForm bean. How can I handle this in Struts framework? The input field I am trying to use will of type select.
Thanks,
Rohit
 
Paul Lester
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have been using Struts for a little of a year and I ran into this same problem some time ago. Truthfully, I never solved it. I couldn't find a way to make Struts do this, so for the one page that uses it, I just "punted" and wrote a servlet to do it.
The closest thing that I found is the DynaActionForm, which just allows you to specify all of the fields in the struts-config.xml file and not have to write your own validation bean ... but you have to know your fields. In your case, you don't know then ahead of them or they may be different each time.
Basically what I did was pass the name, type, and default values as hidden variables to my validation servlet and let it handle the rest. Struts is not well suited to some tasks.
I'll keep reading this forum though to see if someone else knows how to do it. I'm willing to change, but for now, what I have works.
Paul
 
R K Singh
Ranch Hand
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rohit Poddar:
I have a requirement where the HTML form input paramater names are dynamically generated and hence I cannot have them as property in ActionForm bean. How can I handle this in Struts framework? The input field I am trying to use will of type select.
Thanks,
Rohit

Though newbiw to Struts and just two days back I understand power of struts [using struts tag in jsp. Wow its really seperate view from logic, now we need one good editor which can color differently struts tags.]
If you know max number of select then you can have member variables in Form beanm though most of them will be null.
Else you can give same name to all select and then can have one array as member var of FormBean.
 
Rohit Poddar
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I like the idea of same name and array.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic