Managing dynamic form elements in Struts

7 thoughts on “Managing dynamic form elements in Struts”

  1. Hi,
    yes same here it would be great if you can provide me an example code for the above.
    and i think in jsp we can do something like this

    Thanks & Regards,

  2. Hi,
    I started recently to develop struts thing i want to clear from the above.How the dynamically generated form fields are mapped to setValue()and getValue()?
    What should we give in struts-config file?

    Thanks & regards,

  3. Let me give an idea of what I am trying to accomplish and then see if you can feedback.

    Using struts (obviously) I am creating a reusable contact form. It is configured through an xml-config file that defines where the contact form goes and the smtp server it is to use, etc.. I want to set it up so that it does not have to be recompiled upon alternate use. This is one part of a set of components that make it easy for web designers to add functionality to websites they are building using the struts framework (whether they know it or not). i.e. most web designers to not have ide for compiling java classes. So, with those design goals in mind let me share with you my issue.

    The contact form by default captures the Name, Address, City, State, Phone Number, and any other basic contact form info needed. It has an ActionForm bean that captures the input of these predefined items and the data is then passed on to the Action and sent as an email to the recipient. My hangup is… I need to allow the flexibility of adding form elements to the form that are not defined in the ActionForm bean. I would also need to be able to pass the values back to the form in the event that a validation error occurs with the form. With the model the way it is I would have to specifically define the setters and getters in the ActionForm so that the Action could retrive the values of each form element and use them or route them back to the input form for errors or to another Action.

    Is there a way to have a generic getter/setter that can capture any non defined data? For example say a company cleans linen and they want to add a form element that asks for the type of detergent the contactee prefers. The added form element is called “preferredDetergent” yet it is not specifically defined in my ActionForm bean. First, how would I avoid getting an error that says preferredDetergent is not defined in xxxForm? Next, how would I then capture that value in the ActionForm for use in error checking and/or usage in the Action class?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s