[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: when not to use an ActionForm
From:       "Martin Cooper" <martinc () apache ! org>
Date:       2004-04-14 23:10:28
Message-ID: c5kgd5$68o$1 () sea ! gmane ! org
[Download RAW message or body]


"Andy Engle" <struts@andyengle.com> wrote in message
news:20040414225317.90035.qmail@web41504.mail.yahoo.com...
> Vijay.Kukreja@siriuscom.com wrote:
>
> > Richard,
> > Its not necessary to use ActionForm, but it is always better to use
> > one(its my philosophy). But yes it will work the way you are doing
> > it. But i rather prefer a ActionForm which can also help in future
> > for any validation or in future if decided to add more attributes to
> > the form..
>
> With this discussion in mind, I am wondering if there is any way I can
> use an ActionForm in the following scenario: I would like to have a
> list of fields, dynamically created, with names that have been
> dynamically created along with those fields.  So, for example, I would
> have a series of input fields like this:
>
> <input type="text" name="field_1">
> <input type="text" name="field_2">
> <input type="text" name="field_3">
>
> The "field_" part of the name value will stay, but the number will
> change.  With these field name values being so dynamic, is there any
> trick I can use to feed all this into an ActionForm?  I don't think
> there is, unless I am missing something...

I don't believe it can be done with the fields named like that, but there is
a trick you might be able to use. ;-)

1) In the <input> elements, use names of the form "dynaFields.field_1", etc.
The name isn't important, but the dot is.
2) Create a corresponding Map property in your form bean (i.e. a property
named "dynaFields" in this example).

When your action form is populated, you will end up with the "dynaFields"
map containing key/value pairs corresponding to the name/value pairs from
your <input> elements.

--
Martin Cooper


>
>
> Thanks,
> Andy




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic