aspose file tools*
The moose likes Servlets and the fly likes Struts : Dynamic HTML form parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Struts : Dynamic HTML form parameters" Watch "Struts : Dynamic HTML form parameters" New topic
Author

Struts : Dynamic HTML form parameters

Rohit Poddar
Ranch Hand

Joined: Aug 18, 2001
Posts: 36
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


SCJP, SCWCD
Paul Lester
Ranch Hand

Joined: Dec 27, 2002
Posts: 40
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


Where Photography meets vision.<br /><a href="http://www.photogravision.com" target="_blank" rel="nofollow">http://www.photogravision.com</a><br />Please stop by!<br /> <br />SCJP,SCWCD,SCJD,SCEA
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5370
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.


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Rohit Poddar
Ranch Hand

Joined: Aug 18, 2001
Posts: 36
Thanks. I like the idea of same name and array.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts : Dynamic HTML form parameters
 
Similar Threads
Beginner Question: jsp can include non-struts tags?
Struts : Dynamic HTML form parameters
Struts : Dynamic HTML form parameters
Dynamic Struts?
Fundamental struts question