You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Donald Ball <db...@rhoworld.com> on 2002/08/23 19:57:38 UTC

Simple questions regarding DynaActionForms and Map-backed ActionForms

Hi guys. While trying to figure out why the Map-backed ActionForm stuff
mentioned on jguru by Ted Husted doesn't work for us, we ran across Craig's
DynaActionForm classes, which seem to address the same issue. Two
questions:

1. What are the essential differences between the two approaches? Has
anyone had more or less success with one or the other?

2. When I try the DynaActionForm bean like so:

    <form-bean name="SimpleForm"
type="org.apache.struts.action.DynaActionForm">
      <form-property name="foo" initial="1" type="java.lang.String"/>
    </form-bean>

on a form which creates inputs using the "foo" property, I get the form
with a default value of "1" as I expect. However, when I also attempt to
use a "bar" property, which we will pretend is dynamic and is not known at
deployment-time, struts fails, telling me there is no getter method
available for the "bar" property for bean under name
org.apache.struts.taglib.html.BEAN. What's up with this?

My goal is, essentially, to have an ActionForm bean of some kind (Dyna or
Map-backed, doesn't really matter) that can work with a dynamic set of
properties that aren't all known at deployment-time. Any clues for me?
Thanks in advance for any help or pointers.

- donald


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


Re: Simple questions regarding DynaActionForms and Map-backed ActionForms

Posted by "Craig R. McClanahan" <cr...@apache.org>.

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>


Re: Simple questions regarding DynaActionForms and Map-backed ActionForms

Posted by Donald Ball <db...@rhoworld.com>.
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?

And what about DynaActionForm compared to Map-backed ActionForm?

Thanks for the quick response.

- donald


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


Re: Simple questions regarding DynaActionForms and Map-backed ActionForms

Posted by "Craig R. McClanahan" <cr...@apache.org>.
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.

Craig


On Fri, 23 Aug 2002, Donald Ball wrote:

> Date: Fri, 23 Aug 2002 13:57:38 -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: Simple questions regarding DynaActionForms and Map-backed
>     ActionForms
>
> Hi guys. While trying to figure out why the Map-backed ActionForm stuff
> mentioned on jguru by Ted Husted doesn't work for us, we ran across Craig's
> DynaActionForm classes, which seem to address the same issue. Two
> questions:
>
> 1. What are the essential differences between the two approaches? Has
> anyone had more or less success with one or the other?
>
> 2. When I try the DynaActionForm bean like so:
>
>     <form-bean name="SimpleForm"
> type="org.apache.struts.action.DynaActionForm">
>       <form-property name="foo" initial="1" type="java.lang.String"/>
>     </form-bean>
>
> on a form which creates inputs using the "foo" property, I get the form
> with a default value of "1" as I expect. However, when I also attempt to
> use a "bar" property, which we will pretend is dynamic and is not known at
> deployment-time, struts fails, telling me there is no getter method
> available for the "bar" property for bean under name
> org.apache.struts.taglib.html.BEAN. What's up with this?
>
> My goal is, essentially, to have an ActionForm bean of some kind (Dyna or
> Map-backed, doesn't really matter) that can work with a dynamic set of
> properties that aren't all known at deployment-time. Any clues for me?
> Thanks in advance for any help or pointers.
>
> - donald
>
>
> --
> 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>