On Tue, 16 Jul 2002, Roman Fail wrote:

> Date: Tue, 16 Jul 2002 16:34:46 -0700
> From: Roman Fail <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: Rick Reumann <[EMAIL PROTECTED]>,
>      Struts List <[EMAIL PROTECTED]>
> Subject: RE: getting nested tags to work with DynaActionForm???
>
> I had the same problem - after reviewing the source code for
> DynaActionForm I realized that the underlying ArrayList is not
> 'automatically' instantiated by the DynaActionForm.  In other words,
> when the controller is trying to call DynaActionForm.set("myField[0]")
> because it sees a request parameter called 'myField[0]', there is no
> ArrayList there yet to match the "myField" property.  My solution was to
> subclass DynaActionForm and just override the reset() method in order to
> instantiate the ArrayList.  (since reset() is called before any
> setters).  I think I also did this using an array of BasicDynaBeans, and
> again had to initialize the array in reset().
>
>  Of course you don't have to do this when simply displaying the data,
> because you are populating the property with your ArrayList in
> Action.perform()/execute() before the DynaActionForm.get() methods are
> ever called.
>
>  Is there a better solution out there?  I don't like having to write a
> subclass just to instantiate the ArrayList.
>

Setting stuff like this up in the reset() method is the standard approach.
Arrays have to exist already for either standard JavaBean-based
ActionForms, as well as DynaActionForms.

In recent nightly builds, we added support for an additional mechanism --
you can declare an intiialization expression for arrays in the
<form-property> for a DynaActionForm bean, using the "initial" attribute.
The syntax is basically like what you use in Java to initialize an array
to a set of values in a variable declaration -- for example:

  <form-bean name="myform"
             type="org.apache.struts.action.DynaActionForm">

    <form-property name="intArray" type="int[]"
                initial="{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }"/>

  </form-bean>

You can initialize arrays of anything that you've registered a converter
for, and even use strings with embedded whitespace (use single quotes
around the values if you're using double quotes in your XML attributes, or
vice versa).

>  This is another example of where knowing the exact sequence of Struts
> events is crucial.  Has anyone ever written up a detailed step-by-step
> of what the controller does when a request comes in?  I've written a
> brief one for our company's developers - shall I post it?
>

I don't know of any such diagrams off the top of my head, so would be
interested in seeing, say, a UML sequence diagram for this and including
it in the docs.  The important method to look at is
ActionServlet.process() (in Struts 1.0) or RequestProcessor.process (in
Struts 1.1), which is in charge of the entire request processing lifecycle
for each request going through the controller.  Going from there to each
of the processXxxxx methods it calls, and reading the corresponding
JavaDoc comments, will tell you what you need to know.

> Roman Fail
> Sr. Web Application Developer
> POS Portal, Inc.
>

Craig


>
>       -----Original Message-----
>       From: Rick Reumann [mailto:[EMAIL PROTECTED]]
>       Sent: Tue 7/16/2002 1:33 PM
>       To: Struts List
>       Cc:
>       Subject: getting nested tags to work with DynaActionForm???
>
>
>
>       I had an ArrayList property set in my DynaActionForm and it worked
>       fine with the nested tag in displaying the information from the beans
>       in the ArrayList of this DynaActionForm. The problem however came when
>       I when I hit submit with the updated information. I kept getting
>       BeanUtils.populate errors with no index value set for 'field.xxxx[0]'.
>       Sorry can't cite the exact error since I now went to using a typical
>       ActionForm and the nested tag page submits fine.
>
>       Is there something special I need to do in order to get
>       DynamicActionForms to work with Nested tags?
>
>       Thanks,
>
>       --
>
>       Rick
>       mailto:[EMAIL PROTECTED]
>
>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to