Re: Re[2]: getting nested tags to work with DynaActionForm???
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 [EMAIL PROTECTED] To: Craig R. McClanahan [EMAIL PROTECTED] Cc: Struts Users Mailing List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] Craig -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re[2]: getting nested tags to work with DynaActionForm???
What do you think of Arron's idea, Craig? It would be ten times more intuitive to have DynaForms work more like an ArrayList - you instantiate the form, call an indexed setter and it just works - no exceptions. Rick and I are merely the first of many who will hit this annoying, counter-intuitive, undocumented speed bump. Rick finally gave up and just went back to regular ActionForms, and I came close to that before I figured it out. I haven't looked into the lazy collections code yet, but it sounds like a great solution. Roman -Original Message- From: Arron Bates [mailto:[EMAIL PROTECTED]] Sent: Wed 7/17/2002 5:28 AM To: Struts Users Mailing List Cc: Subject: Re: Re[2]: getting nested tags to work with DynaActionForm??? 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 [EMAIL PROTECTED] To: Craig R. McClanahan [EMAIL PROTECTED] Cc: Struts Users Mailing List [EMAIL PROTECTED] 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
Re[2]: getting nested tags to work with DynaActionForm???
On Wed, 17 Jul 2002, Roman Fail wrote: Date: Wed, 17 Jul 2002 15:23:23 -0700 From: Roman Fail [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re[2]: getting nested tags to work with DynaActionForm??? What do you think of Arron's idea, Craig? It would be ten times more intuitive to have DynaForms work more like an ArrayList - you instantiate the form, call an indexed setter and it just works - no exceptions. Rick and I are merely the first of many who will hit this annoying, counter-intuitive, undocumented speed bump. Rick finally gave up and just went back to regular ActionForms, and I came close to that before I figured it out. Counter-intuitive to whom? Do standard JavaBean indexed properties act like this? :-) I'd possibly buy into it for java.lang.List based properties, but I'm pretty skeptical about transparently expanding an array that the user has already created. I haven't looked into the lazy collections code yet, but it sounds like a great solution. Lazy instantiation is a neat idea in principle, but there is a whole lot more to it than just nested properties. You really want to be able to configure quite a bit of stuff about the beans that get created, up to and including a custom factory for beans of a particular type. I don't really want to go down that road until we're ready to build a bridge across the chasm at the end of it. Roman Craig -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Re[2]: getting nested tags to work with DynaActionForm???
Counter-intuitive to whom? Do standard JavaBean indexed properties act like this? :-) You've got a great point there. You actually made me realize why it is counter-intuitive though: non-indexed standard JavaBean properties don't do anything on their own either. You have to write the code to store even the simplest property. When I first looked at the DynaFormAction javadocs, I thought I was buying into something that would do everything for me (shame on me, I should have known better!). I wrongly assumed that if the DynaForm would transparently manage getting and setting properties for me. In reality, it only manages non-indexed properties. To do anything with indexed properties, I have to subclass, get inside the black box, and override reset(). I guess I don't really have a problem with that - it's just not documented very well. Perhaps you could add just a bit more discussion about the use of DynaActionForm in the javadoc? I'd possibly buy into it for java.lang.List based properties, but I'm pretty skeptical about transparently expanding an array that the user has already created. Agreed, that does walk into the realm of Big Brother code. I guess it's just going to be a rough spot for DynaNewbies. Thanks for your thoughts. Roman -Original Message- From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]] Sent: Wed 7/17/2002 3:55 PM To: Roman Fail Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re[2]: getting nested tags to work with DynaActionForm??? Date: Wed, 17 Jul 2002 15:23:23 -0700 From: Roman Fail [EMAIL PROTECTED] To: [EMAIL PROTECTED], [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re[2]: getting nested tags to work with DynaActionForm??? What do you think of Arron's idea, Craig? It would be ten times more intuitive to have DynaForms work more like an ArrayList - you instantiate the form, call an indexed setter and it just works - no exceptions. Rick and I are merely the first of many who will hit this annoying, counter-intuitive, undocumented speed bump. Rick finally gave up and just went back to regular ActionForms, and I came close to that before I figured it out. Counter-intuitive to whom? Do standard JavaBean indexed properties act like this? :-) I'd possibly buy into it for java.lang.List based properties, but I'm pretty skeptical about transparently expanding an array that the user has already created. I haven't looked into the lazy collections code yet, but it sounds like a great solution. Lazy instantiation is a neat idea in principle, but there is a whole lot more to it than just nested properties. You really want to be able to configure quite a bit of stuff about the beans that get created, up to and including a custom factory for beans of a particular type. I don't really want to go down that road until we're ready to build a bridge across the chasm at the end of it. Roman Craig
RE: Re[2]: getting nested tags to work with DynaActionForm???
On Wed, 17 Jul 2002, Roman Fail wrote: Date: Wed, 17 Jul 2002 16:17:49 -0700 From: Roman Fail [EMAIL PROTECTED] To: Craig R. McClanahan [EMAIL PROTECTED] Cc: [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: RE: Re[2]: getting nested tags to work with DynaActionForm??? Counter-intuitive to whom? Do standard JavaBean indexed properties act like this? :-) You've got a great point there. You actually made me realize why it is counter-intuitive though: non-indexed standard JavaBean properties don't do anything on their own either. You have to write the code to store even the simplest property. When I first looked at the DynaFormAction javadocs, I thought I was buying into something that would do everything for me (shame on me, I should have known better!). You didn't hear it from me! :-) I wrongly assumed that if the DynaForm would transparently manage getting and setting properties for me. In reality, it only manages non-indexed properties. To do anything with indexed properties, I have to subclass, get inside the black box, and override reset(). I guess I don't really have a problem with that - it's just not documented very well. Perhaps you could add just a bit more discussion about the use of DynaActionForm in the javadoc? The design intent for DynaActionForms was to mimic the level of support that a standard JavaBean does when you do the typical sort of a property with trivial getter and setter methods: String foo = bar; public String getFoo() { return (foo); } public void setFoo(String foo) { this.foo = foo; } Every brand new instance of a standard JavaBean has the foo property pre-initialized to bar. For DynaActionForm beans, you get exactly the same thing by using the initial property: form-bean name=myform form-property name=foo type=java.lang.String initial=bar/ /form-bean Note that the functionality of the initial attribute has been extended in recent nightly builds to support initialization of array properties as well. So, if your standard JavaBean looks like this: String foo[] = { bar, baz }; public String[] getFoo() { return (foo); } public void setFoo(String foo[]) { this.foo = foo; } then you can do the same for a DynaActionForm: form-bean name=myform form-property name=foo type=java.lang.String[] initial={ 'bar', 'baz' }/ /form-bean and you end up with a nicely initialized two-element String array. So, fundamentally, a DynaActionForm is just an ActionForm without the requirement to write the stupid getter and setter methods. Anything fancier, for either kind of form bean, requires code. I'd possibly buy into it for java.lang.List based properties, but I'm pretty skeptical about transparently expanding an array that the user has already created. Agreed, that does walk into the realm of Big Brother code. I guess it's just going to be a rough spot for DynaNewbies. Not any rougher than it is for people trying to understand standard ActionForms :-) Thanks for your thoughts. I think the example code, and all of the good books that are coming out, will help address this need. Roman Craig -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re[2]: getting nested tags to work with DynaActionForm???
On Tue, 16 Jul 2002, Rick Reumann wrote: Date: Tue, 16 Jul 2002 22:04:54 -0400 From: Rick Reumann [EMAIL PROTECTED] To: Craig R. McClanahan [EMAIL PROTECTED] Cc: Struts Users Mailing List [EMAIL PROTECTED] 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:[EMAIL PROTECTED] Craig -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]