On the input side, it sounds like what you want is a map that is basically a
copy of the map usually used internally by the servlet container to
represent parameters. If you don't mind having copies in the map of what's
also in any explicit form bean fields, you could just use this at the top of
the reset() method in your form bean (or a base class).

    HashMap map = new HashMap(); // Actually, this would be an instance
variable
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();)
{
        String name = (String)e.nextElement();
        map.put(name, request.getParameterValues(name));
    }

The output side is a little different because the Struts tags are set up to
look only for explicit fields. There's been at least one proposal for
changing that, though.

However, this is what I refer to as an "uncontrolled" dynamic form bean.
More interesting would be a "controlled" dynamic form bean, where the valid
fields are actually controlled externally, rather than being at the whim of
the request (or other code). But then, that's a bunch more work. :-)

--
Martin Cooper


----- Original Message -----
From: "John Townsend" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "'Luis Olivares'"
<[EMAIL PROTECTED]>
Sent: Wednesday, August 29, 2001 12:19 PM
Subject: RE: Dynamic Form Beans?


> The one idea that I had was to create a new subclass of ActionForm
> called ActionDataForm. This form would have get and put methods that use
> keys instead of the usual pattern of numerous getters/setters.
>
>
> For the process of saving form data, we could add a new override to
> RequestUtils.processPopulate(..) which would take an ActionDataForm
> instead of an ActionForm as its form instance. Then we would implement
> this method to use get and put with keys instead of getters/setters.
>
> One problem: I don't know how the populate works from the other side
> (meaning when you want to prepopulate a form based on the contents of a
> JavaBean in the session, etc.). I imagine that logic is contained in the
> HTML tag libraries or some other tag library.
>
> I guess what I am wondering is that since a number of people have run
> into this and needed a solution I assumed that there might already be a
> solution to this problem. If not, maybe we can find a solution and then
> submit a patch to Struts for 1.1 or something.
>
> Anyone else have any thoughts on this?
>
> -- John Townsend
>
> PS. One thing I just thought of: I wonder if there is a JavaBeans
> solution to this problem? If there is, that might be a better way to go.
>
>
> -----Original Message-----
> From: Luis Olivares [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 29, 2001 11:28 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Dynamic Form Beans?
>
> I have the same 'problem'.
>
> I would like to be able to create a form dynamically depending on the
> structure of a table (I used to do this with 'plain' JSP).
> Any ideas?
>
> Regards.
>                        Luis Olivares.
>            [EMAIL PROTECTED]
>    --------------------------------------------------------------
>   "Intelligence is the ability to avoid doing
>        work, yet getting the work done"
>                   --Linus Torvalds--
>
> ----- Original Message -----
> From: "John Townsend" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, August 29, 2001 12:54 PM
> Subject: Dynamic Form Beans?
>
>
> > I am working on a project where is would be nice to have the ability
> to
> > define a dynamic form bean (i.e. a form bean where the fields are
> > defined at runtime). The most obvious (but perhaps not the best)
> > solution to this problem would be if the ActionServlet could handle
> > saving data in a form bean that was a hashtable.
> >
> > Has someone else run into this problem and come up with a solution?
> >
> > Thanks,
> > -- John Townsend
> >
>


Reply via email to