Re: getting nested tags to work with DynaActionForm???
We want the form beans to stay in session, so it has to be able to be populated when build from an empty constructor (the way beans do). Enter lists of nested objects. In the constructor you have to instantiate the list, new ArrayList() or whatever. So, new request comes in for monkey number five. But our list is only just built, no objects waiting at index number five to take the items, information is lost forever. One way you can track it, is to store the information someplace as to how many are in the list, and build the list in the reset method or whatever. Not easy unless you give the bean access to the request object... which is bad. Enter lazy lists. When you build your array list, wrap it in the lazy list, when you do so, you pass it the definition/means to build objects for the lists. Your definition. Three options, pass it a class definition and it'll simply do a newInstance() on it, the class definition and argument details so it can call a constructor with arguments, or for the most complex, you can define a factory impl against an interface. 99% of the time the class def is all you'll need. For lists within lists... all you can to do is wrap the lists in the child objects and they'll grow just fine too. Why all this?... because from very simple beans you can just forget them, leave the scope as request, and rest assured all the lists or whatever are all built and ready to go. It's just another one of those things that Struts can do for you. I'm going to work them into DynaBeans for my own use at least, because then it's all marked up... don't have to touch anything, nothing has to be explicitly handled for collections. It's not mandatory... can easily specify a build-lists=true in the definition of the property. Specs are great for defining minimum involvement. It is true that a half complete spec implementation isn't a good thing at all, but I'm of the belief that for projects like this a spec should never define the limit of a product. Must admit Craig baffles me on this topic at times. Stuff like this lazy list thing because it's not in the bean spec, but yet I don't see nested dot notation properties and mapped properties in the bean spec either. :) The bean spec has aged a bit, mapped properties and whatever. Not that lazy lists should ever be in it. But... Struts is in the business of providing a cohesive, productive framework for creating applications defined by excellence in design. It does so many things correctly and automatically for you. Excellent. Wrapping my collections in lazy lists to my beans was one more step in me knowing my forms beans are happening correctly, the definition, request scope, the whole deal... one more thing I don't have to code any longer. Less code doing the right stuff is a good thing, hang any spec, IMHO :) Arron. On Fri, 2002-07-19 at 06:04, Adam Hardy wrote: 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 [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
Re: getting nested tags to work with DynaActionForm???
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 [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
Re: getting nested tags to work with DynaActionForm???
I am now using nested tags everywhere and not programming my action forms with getter and setter methods for anything except one or two properties, and the nested beans of course. Is there any reason to regard this as bad practice? I also write my value beans with two properties for every real property, one is typed, e.g. Date, and the other is the string representation of the type. So I also have two getters and two setters. Also again I have the validation code in the value bean which populates the typed property from the string representation property. The action form loops through the beans calling the validate methods. It means I have all my properties in one bean rather than also in the form bean - easier to change when the entity changes. Adam Craig R. McClanahan wrote: On Wed, 17 Jul 2002, Rick Reumann wrote: Date: Wed, 17 Jul 2002 20:57:26 -0400 From: Rick Reumann [EMAIL PROTECTED] To: Craig R. McClanahan [EMAIL PROTECTED] Cc: Roman Fail [EMAIL PROTECTED], Struts Users Mailing List [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: Re[4]: getting nested tags to work with DynaActionForm??? On Wednesday, July 17, 2002, 7:39:23 PM, Craig wrote: Agreed, that does walk into the realm of Big Brother code. I guess it's just going to be a rough spot for DynaNewbies. CRM Not any rougher than it is for people trying to understand standard CRM ActionForms :-) Correct me if I'm wrong here Craig, but where I noticed it was quite a bit more difficult is when you decide not to use Session scope for FormBeans that have ArrayLists with beans inside that also have ArrayLists (etc. with nesting ). I say this because if I remember correctly isn't one of the main differences between the DynaActionForm and the standard ActionForm is that the DynaActionForm ALWAYS calls the reset method (regardless of scope) whereas the ActionForm only calls it when in it's in request scope (or explicitly called?). This is where I think I was running into trouble, since even though my DynaActionForm had session scope it was always calling reset whereas my standard ActionForm in session scope was not calling it. That's not quite accurate. Struts (all versions) always calls reset() when you flow through the controller servlet. However, if you went directly to a JSP page, and the html:form tag creates the form bean (quite common if the form bean is defined to be in request scope), Struts 1.0 did not call reset() but Struts 1.1 does. In the 1.1 case, it makes no difference at all whether it is an ActionForm or a DynaActionForm. So in my case if I wanted request scope for the ActionForm I still would have had to override the reset method to provide a way to initialize the ArrayLists (and I take it the beans inside with ArrayLists as well). That is true for both kinds of beans. In either case, you can also choose to make the constructor do this sort of initialization (requires a DynaActionForm subclass in the dynamic case, but it's still possible). In my case however it's not too big of a deal that this UserFormBean hang around for a while with Session scope so it seems much easier to use it with an ActionForm than with the DynaActionForm (since with the later case I'm forced to override the reset method and populate nested beans). That should be the case for either kind of form bean. Can you show me an example of where it's different? This is probably a dumb question and I suppose I could try it before posting, but what would happen if I just wanted to use the DynaActionForm in session scope and then just overrode the reset method to do nothing? You'd mess up the initializations based on the initial attribute :-). Wouldn't it still keep the values in the DynaActionForm since it had session scope and wouldn't try to set up unitialized ArrayLists, etc? (of course this would only help if the bean was in Session scope..but just curious if it would even work). Thanks again for all of your comments so far It might do what you want, but for the wrong reasons. I think it's time to get into specific use cases to further this discussion. -- 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: 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[3]: getting nested tags to work with DynaActionForm???
Craig and company, I'll comment some more below but I want to first explain what needs to be set up and handled. I have an ArrayList of beans. Each bean in this ArrayList also contains an ArrayList of String object. On my JSP I'm using the nested tag (new to using it- bannana stuff very helpful Arron) to create the dynamically created form. ( Picture a JSP that was to display a dynamic list of cars and for each car there would be list of particular styles you could pick from). On Tuesday, July 16, 2002, 10:45:11 PM, Craig wrote: CRM If you're using request scope beans, a new instance gets created on every CRM request. And I will bet that you probably have an initialization of this CRM array happening in your constructor, or in an initialization expression, CRM right? Yes, I believe so. A DTO is populated with the ArrayList of beans and then the DTO is converted to the DynaActionForm which is set into request scope. (The nested tag and display of the information on the page is working beautifully..problem is upon submission). 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? CRM That's definitely a place where loading the arrays in the reset() method CRM makes sense. Ok, well what I've done is added this to the base class that my DynaActionForm (actually DynaValidatorForm) extends (Roman on this list was helping me with this) (20 is just an arbitrary number greater than the amount that would be displayed on the form): public class UserDynaForm extends DynaValidatorForm { public void reset( ActionMapping mapping, HttpServletRequest request ) { ArrayList applicationGroups = new ArrayList(); for (int i=0; i 20; i++) { ApplicationGroupBean b = new ApplicationGroupBean(); b.setRoles( new ArrayList() ); applicationGroups.add(b); } set(applicationGroups, applicationGroups); } } I then still have in my struts-config, for this form: form-bean name=userForm dynamic=true type=corporate.userAdmin.UserDynaForm: form-property name=applicationGroups type=java.util.ArrayList/ The page will display the initial information fine. When I submit now, however, the problem is it's trying to submit nulls. It's as if it doesn't pick up what was selected on the JSP and this reset is wiping out what was selected? I'm sure I'm missing something simple so sorry for my ignorance. I guess what is so odd is that when I switch to using a standard ActionForm I don't have to override the reset and the page submits fine. Thanks for the help. -- Rick mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re[4]: getting nested tags to work with DynaActionForm???
Actually I just realized part of the problem below is/was is that even using the standard ActionForm I can't seem to get the nested ArrayList stuff to take upon submission unless I give the form session scope. I'm sure this question has been answered before so I'll look in the archives ( although I must admit the searching ability on the archives for this struts list is not the greatest ) If someone does have comments don't hesitate to send them. Thanks Rick On Wednesday, July 17, 2002, 11:24:10 AM, Rick wrote: RR Craig and company, RR I'll comment some more below but I want to first explain what needs to RR be set up and handled. I have an ArrayList of beans. Each bean in this RR ArrayList also contains an ArrayList of String object. On my JSP I'm RR using the nested tag (new to using it- bannana stuff very helpful RR Arron) to create the dynamically created form. ( Picture a JSP that RR was to display a dynamic list of cars and for each car there would be RR list of particular styles you could pick from). RR On Tuesday, July 16, 2002, 10:45:11 PM, Craig wrote: CRM If you're using request scope beans, a new instance gets created on every CRM request. And I will bet that you probably have an initialization of this CRM array happening in your constructor, or in an initialization expression, CRM right? RR Yes, I believe so. A DTO is populated with the ArrayList of beans RR and then the DTO is converted to the DynaActionForm which is set RR into request scope. (The nested tag and display of the RR information on the page is working beautifully..problem is upon RR submission). 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? CRM That's definitely a place where loading the arrays in the reset() method CRM makes sense. RR Ok, well what I've done is added this to the base class that my RR DynaActionForm (actually DynaValidatorForm) extends (Roman on RR this list was helping me with this) (20 is just an arbitrary RR number greater than the amount that would be displayed on the RR form): RR public class UserDynaForm extends DynaValidatorForm { RR public void reset( ActionMapping mapping, HttpServletRequest request ) { RR ArrayList applicationGroups = new ArrayList(); RR for (int i=0; i 20; i++) { RR ApplicationGroupBean b = new ApplicationGroupBean(); RR b.setRoles( new ArrayList() ); RR applicationGroups.add(b); RR } RR set(applicationGroups, applicationGroups); RR } RR } RR I then still have in my struts-config, for this form: RR form-bean name=userForm RR dynamic=true RR type=corporate.userAdmin.UserDynaForm: RR form-property name=applicationGroups type=java.util.ArrayList/ RR RR The page will display the initial information fine. When I submit now, RR however, the problem is it's trying to submit nulls. It's as if it RR doesn't pick up what was selected on the JSP and this reset is wiping RR out what was selected? RR I'm sure I'm missing something simple so sorry for my ignorance. I RR guess what is so odd is that when I switch to using a standard RR ActionForm I don't have to override the reset and the page submits RR fine. RR Thanks for the help. -- Rick mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: getting nested tags to work with DynaActionForm???
Subject: Re: getting nested tags to work with DynaActionForm??? From: Serge Shikov [EMAIL PROTECTED] === Craig R. McClanahan wrote: 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. Craig, could you give some examples for nested property initialization? How to initialize DynaForm with nested properties like . - what should I specify in initial attribute for (if any)? -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: getting nested tags to work with DynaActionForm???
On Wed, 17 Jul 2002, Struts Newsgroup wrote: Date: Wed, 17 Jul 2002 10:55:01 -0700 From: Struts Newsgroup [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: getting nested tags to work with DynaActionForm??? Subject: Re: getting nested tags to work with DynaActionForm??? From: Serge Shikov [EMAIL PROTECTED] === Craig R. McClanahan wrote: 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. Craig, could you give some examples for nested property initialization? How to initialize DynaForm with nested properties like . - what should I specify in initial attribute for (if any)? You'll have to do nested initialization like this on your own, in either the reset() method or perhaps in a constructor. The initial attribute only works for one-level setting, and only for the restricted cases where you can convert the initial value from the initial string. 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]
Struts event sequence (WAS: getting nested tags to work with DynaActionForm???)
This is the very basic outline of Struts events (with some helpful comments) that I worked up when I was using Struts 1.0, although most of it is still the same. Basically I've just expanded steps 3 4 of Dan's diagram a bit. Chapter 5 of Chuck's book is much more detailed than this, and an excellent resource (Thanks, Chuck!). In fact I think chapter 5 might be a bit overwhelming for a newbie, and reading the ever-changing Struts source code is not comfortable at first. I've found that this little outline has helped our new Struts developers a lot. Craig suggested a nice UML sequence diagram for the docs, which would be great - but I'm not fluent in UML yet. Here's my document - keep in mind it's been about a year since I wrote this, but I'd be happy to take suggestions on updating it: http://www.posportal.com/StrutsOverview.html Roman Fail Sr. Web Application Developer POS Portal, Inc. -Original Message- From: Dan Cancro [mailto:[EMAIL PROTECTED]] Sent: Tue 7/16/2002 5:00 PM To: 'Struts Users Mailing List' Cc: Subject: RE: getting nested tags to work with DynaActionForm??? I'd like to see what you've written. Here's how I understand it so far: http://members.telocity.com/dcancro/images/eng/Struts_MVC.gif -Original Message- From: Roman Fail [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 16, 2002 4:35 PM To: Rick Reumann; Struts List 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. 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? Roman Fail Sr. Web Application Developer POS Portal, Inc. -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.[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]
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[4]: getting nested tags to work with DynaActionForm???
On Wednesday, July 17, 2002, 7:39:23 PM, Craig wrote: Agreed, that does walk into the realm of Big Brother code. I guess it's just going to be a rough spot for DynaNewbies. CRM Not any rougher than it is for people trying to understand standard CRM ActionForms :-) Correct me if I'm wrong here Craig, but where I noticed it was quite a bit more difficult is when you decide not to use Session scope for FormBeans that have ArrayLists with beans inside that also have ArrayLists (etc. with nesting ). I say this because if I remember correctly isn't one of the main differences between the DynaActionForm and the standard ActionForm is that the DynaActionForm ALWAYS calls the reset method (regardless of scope) whereas the ActionForm only calls it when in it's in request scope (or explicitly called?). This is where I think I was running into trouble, since even though my DynaActionForm had session scope it was always calling reset whereas my standard ActionForm in session scope was not calling it. So in my case if I wanted request scope for the ActionForm I still would have had to override the reset method to provide a way to initialize the ArrayLists (and I take it the beans inside with ArrayLists as well). In my case however it's not too big of a deal that this UserFormBean hang around for a while with Session scope so it seems much easier to use it with an ActionForm than with the DynaActionForm (since with the later case I'm forced to override the reset method and populate nested beans). This is probably a dumb question and I suppose I could try it before posting, but what would happen if I just wanted to use the DynaActionForm in session scope and then just overrode the reset method to do nothing? Wouldn't it still keep the values in the DynaActionForm since it had session scope and wouldn't try to set up unitialized ArrayLists, etc? (of course this would only help if the bean was in Session scope..but just curious if it would even work). Thanks again for all of your comments so far -- Rick mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re[4]: getting nested tags to work with DynaActionForm???
On Wed, 17 Jul 2002, Rick Reumann wrote: Date: Wed, 17 Jul 2002 20:57:26 -0400 From: Rick Reumann [EMAIL PROTECTED] To: Craig R. McClanahan [EMAIL PROTECTED] Cc: Roman Fail [EMAIL PROTECTED], Struts Users Mailing List [EMAIL PROTECTED], [EMAIL PROTECTED] Subject: Re[4]: getting nested tags to work with DynaActionForm??? On Wednesday, July 17, 2002, 7:39:23 PM, Craig wrote: Agreed, that does walk into the realm of Big Brother code. I guess it's just going to be a rough spot for DynaNewbies. CRM Not any rougher than it is for people trying to understand standard CRM ActionForms :-) Correct me if I'm wrong here Craig, but where I noticed it was quite a bit more difficult is when you decide not to use Session scope for FormBeans that have ArrayLists with beans inside that also have ArrayLists (etc. with nesting ). I say this because if I remember correctly isn't one of the main differences between the DynaActionForm and the standard ActionForm is that the DynaActionForm ALWAYS calls the reset method (regardless of scope) whereas the ActionForm only calls it when in it's in request scope (or explicitly called?). This is where I think I was running into trouble, since even though my DynaActionForm had session scope it was always calling reset whereas my standard ActionForm in session scope was not calling it. That's not quite accurate. Struts (all versions) always calls reset() when you flow through the controller servlet. However, if you went directly to a JSP page, and the html:form tag creates the form bean (quite common if the form bean is defined to be in request scope), Struts 1.0 did not call reset() but Struts 1.1 does. In the 1.1 case, it makes no difference at all whether it is an ActionForm or a DynaActionForm. So in my case if I wanted request scope for the ActionForm I still would have had to override the reset method to provide a way to initialize the ArrayLists (and I take it the beans inside with ArrayLists as well). That is true for both kinds of beans. In either case, you can also choose to make the constructor do this sort of initialization (requires a DynaActionForm subclass in the dynamic case, but it's still possible). In my case however it's not too big of a deal that this UserFormBean hang around for a while with Session scope so it seems much easier to use it with an ActionForm than with the DynaActionForm (since with the later case I'm forced to override the reset method and populate nested beans). That should be the case for either kind of form bean. Can you show me an example of where it's different? This is probably a dumb question and I suppose I could try it before posting, but what would happen if I just wanted to use the DynaActionForm in session scope and then just overrode the reset method to do nothing? You'd mess up the initializations based on the initial attribute :-). Wouldn't it still keep the values in the DynaActionForm since it had session scope and wouldn't try to set up unitialized ArrayLists, etc? (of course this would only help if the bean was in Session scope..but just curious if it would even work). Thanks again for all of your comments so far It might do what you want, but for the wrong reasons. I think it's time to get into specific use cases to further this discussion. -- Rick mailto:[EMAIL PROTECTED] Craig -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
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.[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]
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. 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? Roman Fail Sr. Web Application Developer POS Portal, Inc. -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.[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]
RE: getting nested tags to work with DynaActionForm???
In answer to this question, take a look at several of the chapters from my upcoming O'Reilly book on Struts, especially chapter 5 where I cover the steps that the controller goes through while processing a request. http://www.theserverside.com/resources/strutsreview.jsp chuck 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? Roman Fail Sr. Web Application Developer POS Portal, Inc. -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.[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]
RE: getting nested tags to work with DynaActionForm???
I'd like to see what you've written. Here's how I understand it so far: http://members.telocity.com/dcancro/images/eng/Struts_MVC.gif -Original Message- From: Roman Fail [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 16, 2002 4:35 PM To: Rick Reumann; Struts List 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. 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? Roman Fail Sr. Web Application Developer POS Portal, Inc. -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.[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]
RE: getting nested tags to work with DynaActionForm???
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 processX 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.[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]
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]