struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <ahardy.str...@cyberspaceroad.com>
Subject Re: getting nested tags to work with DynaActionForm???
Date Thu, 18 Jul 2002 20:04:54 GMT
Arron,
I wonder how your lazy initialisation works. I'm afraid I didn't look at 
the code - since you said you wanted to explain it to the masses anyway, 
perhaps you won't mind explaining, rather than telling me not to be so 
lazy myself. Basically, if you have your example:

In the request parameters:

monkey[1].bunch[2].banana[3].color

how does your collection wrapper know what class to instantiate for 
monkey, bunch, etc etc? Is this something that you configure in xml 
somewhere? Presumably an extension to dynaform configuration?


Adam


Arron Bates wrote:
> Craig, wouldn't this be fixed by getting the collections in the DynaForm
> to be wrapped by the lazy lists I commited a few weeks ago to
> commons?... then when they're being created when the request comes in,
> it'll all grow as needed and it'd just happen.
> 
> 
> Been missing the past couple of weeks due to bad flu among other things.
> Love to get in there and code it, but time is hard to find at the moment
> and there's other things I need to get on to, but the above feels like a
> good marriage.
> 
> One of the things I have to do is describe the lazy collections to the
> masses. Seems a few have had list constrcution issues with request scope
> beens in the last fortnight.
> 
> 
> 
> On Wed, 2002-07-17 at 12:45, Craig R. McClanahan wrote:
> 
>>
>>On Tue, 16 Jul 2002, Rick Reumann wrote:
>>
>>
>>>Date: Tue, 16 Jul 2002 22:04:54 -0400
>>>From: Rick Reumann <maillist@reumann.net>
>>>To: Craig R. McClanahan <craigmcc@apache.org>
>>>Cc: Struts Users Mailing List <struts-user@jakarta.apache.org>
>>>Subject: Re[2]: getting nested tags to work with DynaActionForm???
>>>
>>>On Tuesday, July 16, 2002, 9:04:04 PM, Craig R. McClanahan wrote:
>>>
>>>CRM> Setting stuff like this up in the reset() method is the standard approach.
>>>CRM> Arrays have to exist already for either standard JavaBean-based
>>>CRM> ActionForms, as well as DynaActionForms.
>>>
>>>     I'm still a bit confused by this. When I use a standard
>>>     ActionForm I don't have to do anything special with my ArrayList
>>>     in the ActionForm. A page that uses this ArrayList works fine.
>>>     However as soon as I try to use this ArrayList as property in a
>>>     DynaActionForm I run into problems trying to submit a jsp page
>>>     that was populated with the ArrayList info (the display works
>>>     fine, it's just upon submission).
>>>
>>
>>If you're using request scope beans, a new instance gets created on every
>>request.  And I will bet that you probably have an initialization of this
>>array happening in your constructor, or in an initialization expression,
>>right?
>>
>>For DynaActionForm instances, the default initialization of all
>>non-primitives in null.  That's why you still need to initialize in
>>reset(), or use the new "initial" property described below.
>>
>>
>>>CRM> In recent nightly builds, we added support for an additional mechanism
--
>>>CRM> you can declare an intiialization expression for arrays in the
>>>CRM> <form-property> for a DynaActionForm bean, using the "initial" attribute.
>>>CRM> The syntax is basically like what you use in Java to initialize an array
>>>CRM> to a set of values in a variable declaration -- for example:
>>>
>>>CRM>   <form-bean name="myform"
>>>CRM>              type="org.apache.struts.action.DynaActionForm">
>>>
>>>CRM>     <form-property name="intArray" type="int[]"
>>>CRM>                 initial="{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }"/>
>>>
>>>CRM>   </form-bean>
>>>
>>>       What if the information in an ArrayList of beans that you want in a
>>>       DynaActionForm is to first be populated by some database info.
>>>       Do you need to first initialize it like a above to a bunch of
>>>       nulls? If so what if the list size fluctuates (hence use of
>>>       ArrayList) how do you know how many to initialize the ArrayList
>>>       with?
>>>
>>
>>That's definitely a place where loading the arrays in the reset() method
>>makes sense.
>>
>>Having an "intArray" property of type "int[]" on a DynaBean is very much
>>like having the following method signatures on a standard JavaBean:
>>
>>  public int[] getIntArray();
>>  public void setIntArray(int intArray[]);
>>
>>so you don't have to pre-initialze the array to nulls or anything.  Just
>>set up the array you want as a local variable (of any desired
>>length), populate its values, and call:
>>
>>  int intArray[] = ...;
>>  dynaform.set("intArray", intArray);
>>
>>One really common scenario is that you don't know ahead of time how many
>>items you're going to read from the database.  An approach I use a lot is
>>to use an ArrayList to accumulate the values, then convert them to an
>>array.  Something like this (assuming you have a "labels" property of
>>type "java.lang.String[]"):
>>
>>  ArrayList temp = new ArrayList();
>>  Connection conn = ...;
>>  Statement stmt = conn.createStatement();
>>  ResultSet rs = stmt.executeQuery("select label from customer_types");
>>  while (rs.next()) {
>>    temp.add(rs.getString(1));
>>  }
>>  String labels[] = (String[]) temp.toArray(new String[temp.size()]);
>>  dynaFormBean.set("labels", labels);
>>
>>Alternatively, you could set your property type to java.util.List instead
>>-- all the Struts tags that support indexed access against arrays work
>>perfectly well against a List as well.
>>
>>
>>>       Thanks for any more thoughts.
>>>
>>>--
>>>
>>>Rick
>>>
>>>mailto:maillist@reumann.net
>>>
>>>
>>
>>Craig
>>
>>
>>
>>--
>>To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 
> 



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


Mime
View raw message