You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hardee, Tony" <To...@ps.net> on 2002/08/23 20:48:19 UTC

RE: Simple questions regarding DynaActionForms and Map-backed A ctionForms

>> However, DynaActionForm isn't real graceful about creating the actual Map
>> instance for you, and if it's not there already you'll run into NPEs.
The
>> usual answer is to subclass DynaActionForm and create the Map in the
>> reset() method ...

Suggestion, why not extend the form-property specification to allow
something like:
  <form-property
    name="map"
    not-null="true"
    resetMethodName="clear"
    type="java.util.map"/>
  
The presence of the not-null="true" would signal that the default
constructor be invoked when initializing the attribute as opposed to setting
the attribute to null.  The resetMethodName would contain the name of the
zero parameter method to invoke during the form reset.


-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org]
Sent: Friday, August 23, 2002 2:25 PM
To: Struts Users Mailing List; dball@rhoworld.com
Subject: Re: Simple questions regarding DynaActionForms and Map-backed
ActionForms




On Fri, 23 Aug 2002, Donald Ball wrote:

> Date: Fri, 23 Aug 2002 14:14:23 -0400
> From: Donald Ball <db...@rhoworld.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>      dball@rhoworld.com
> To: struts-user@jakarta.apache.org
> Subject: Re: Simple questions regarding DynaActionForms and Map-backed
>     ActionForms
>
> On 8/23/2002 at 11:06 AM Craig R. McClanahan wrote:
>
> >Unfortunately for your requirement, DynaActionForm form beans are not
> >"dynamic" in the sense that you can have completely dynamic *sets* of
> >properties.  They only save you from having to create the form bean class
> >itself.
> >
> >One approach would be to use a property that is a Map, and use the mapped
> >property getter/setter syntax.
>
> That was going to be my next question, as it seemed suspiciously
> potentially useful. Is there sample code or a HOWTO floating around out
> there anywhere?
>

Consider a mapped property named "map" (sorry, not very imaginative this
morning :-).  You decide that you need input fields for "foo" and "bar",
so you create input fields like this:

  <html:text property="map(foo)"/>

  <html:text property="map(bar)"/>

using the "()" syntax that PropertyUtils supports for mapped property
lookups.

> And what about DynaActionForm compared to Map-backed ActionForm?
>

You can use a mapped property with either kind of form bean -- the "dyna"
version would be declared like this:

  <form-bean name="mybean" ...>
    <form-property name="map" type="java.util.Map"/>
    ...
  </form-bean>

However, DynaActionForm isn't real graceful about creating the actual Map
instance for you, and if it's not there already you'll run into NPEs.  The
usual answer is to subclass DynaActionForm and create the Map in the
reset() method -- but if you're going to subclass anyway, a standard
ActionForm bean with a single mapped property might be just as easy to
deal with (you can create the Map instance in the constructor).

So it's probably an either-or, driven more by what else you've got in the
form bean versus this particular decision.

> Thanks for the quick response.
>
> - donald

Craig


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>