RE: 2D Collection and nested:iterate
Thanks for the reply, appreciate it. From what I understand, I have to do something like : firstList --eachElementIs-- simpleBean --contains-- secondList In other words, wrap the 2nd list inside a bean. However, if that's the cast, I would imagine it will drag down the performance of our application by quite a bit due to Objects instantiation. (the 2D collection get used a lot and the collections are quite large). Is there anyway around it so that I can still use the original data structure ? Again, thanks for the input. :) If performance is that much of an issue, I'd square up the use of the lists. If it's all random acces (like accessing through the BeanUtils system) then ArrayLists are sweet, but if your processing is running through linearly then the LinkedList is the better bet. Just thought I'd mention it. As for the problem at hand... there's not all that much you can do really. One option, if you know that the model is thread safe (like, only one user will be on it at a time ie: request scope/everything but application scope), then you can fake it by making a bean that turns in on itself. By this I mean to make a bean that holds these multi-dimensioned arrays and takes note of the indexes requested. When the child array is sought after, return a reference to itself noting the index. The child index will come in, do the same, store the index and then return the same object. Throw in an extra stage (using the nested:property tag to put in a fake level). We know that when this is called it needs a real object, from which you can offer up the multi-dimmed object. eg:... start crappy code private int parentIndex; private int childIndex; private ArrayList myData; public Object getParentList(int i) { this.parentIndex = i; return this; } public Object getChildList(int i) { this.childIndex = i; return this; } public Object getFakeProperty() { return ((ArrayList)myData.get(parentIndex)).get(childIndex); } /end crappy code ...catch my drift? I've done a fake properties like this, and they work sweet. I haven't done it for two sequential lists, but the theory is sound. It's the fake property brings it all back together telling the object that it has to pull its finger out and actually fetch the object you're after. The above will remove the overhead of all the object creation. It has to be thread safe because if another thread gets in there inbetween a thread reading the first index and the second, it'll all be out of whack. If the list is build for a particular user, there shouldn't be any issues. ...explanation fuzzy at all?... outside of this, there's no option that comes to mind. Note: if you want to access a property of the object of the first list (the bean theoretically holding the other list), you'll have to make another fake property to identify you want that object. eg: public Object getFirstLevelFake() { return (ArrayList)myData.get(parentIndex); } ...outside of all the stuff spieled on above, ie: once you've broken through that second list or have reference to the parent list object, you can keep nesting as usual. Hopefully I've said all that clear enough for you to move forward :) Arron. -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
RE: 2D Collection and nested:iterate
Thx Aaron. That solution works great for displaying the data. However, Struts will not know how to populate the List back when the data is received from the user, since the Indices cannot be set in that access wrapper object. -Original Message- From: Arron Bates [mailto:struts-user;keyboardmonkey.com] Sent: Wednesday, November 13, 2002 7:31 AM To: Struts Users Mailing List Subject: RE: 2D Collection and nested:iterate Thanks for the reply, appreciate it. From what I understand, I have to do something like : firstList --eachElementIs-- simpleBean --contains-- secondList In other words, wrap the 2nd list inside a bean. However, if that's the cast, I would imagine it will drag down the performance of our application by quite a bit due to Objects instantiation. (the 2D collection get used a lot and the collections are quite large). Is there anyway around it so that I can still use the original data structure ? Again, thanks for the input. :) If performance is that much of an issue, I'd square up the use of the lists. If it's all random acces (like accessing through the BeanUtils system) then ArrayLists are sweet, but if your processing is running through linearly then the LinkedList is the better bet. Just thought I'd mention it. As for the problem at hand... there's not all that much you can do really. One option, if you know that the model is thread safe (like, only one user will be on it at a time ie: request scope/everything but application scope), then you can fake it by making a bean that turns in on itself. By this I mean to make a bean that holds these multi-dimensioned arrays and takes note of the indexes requested. When the child array is sought after, return a reference to itself noting the index. The child index will come in, do the same, store the index and then return the same object. Throw in an extra stage (using the nested:property tag to put in a fake level). We know that when this is called it needs a real object, from which you can offer up the multi-dimmed object. eg:... start crappy code private int parentIndex; private int childIndex; private ArrayList myData; public Object getParentList(int i) { this.parentIndex = i; return this; } public Object getChildList(int i) { this.childIndex = i; return this; } public Object getFakeProperty() { return ((ArrayList)myData.get(parentIndex)).get(childIndex); } /end crappy code ...catch my drift? I've done a fake properties like this, and they work sweet. I haven't done it for two sequential lists, but the theory is sound. It's the fake property brings it all back together telling the object that it has to pull its finger out and actually fetch the object you're after. The above will remove the overhead of all the object creation. It has to be thread safe because if another thread gets in there inbetween a thread reading the first index and the second, it'll all be out of whack. If the list is build for a particular user, there shouldn't be any issues. ...explanation fuzzy at all?... outside of this, there's no option that comes to mind. Note: if you want to access a property of the object of the first list (the bean theoretically holding the other list), you'll have to make another fake property to identify you want that object. eg: public Object getFirstLevelFake() { return (ArrayList)myData.get(parentIndex); } ...outside of all the stuff spieled on above, ie: once you've broken through that second list or have reference to the parent list object, you can keep nesting as usual. Hopefully I've said all that clear enough for you to move forward :) Arron. -- 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
RE: 2D Collection and nested:iterate
Thx Aaron. Arron? - Why? My dad was hilarious back in his day. :P That solution works great for displaying the data. However, Struts will not know how to populate the List back when the data is received from the user, since the Indices cannot be set in that access wrapper object. Well... the mechanism the tags use to display is the same as the mechanism the server uses to update, BeanUtils. So I'm guessing that it's the old Struts can populate lists... thing. Try it again while keeping the bean in the session scope. It should work. To get it back out of session scope and into the request scope, you'll have to employ the technique of the LazyList stuff in the commons-collections project. Look for the LazyList docco in the org.apache.commons.collections.ListUtils class. This will allow you to wrap your ArrayList (without any real overhead), and allow it to grow automatically when all those indexed items come back in. Arron. * you've got rail! -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
Re: 2D Collection and nested:iterate
The problem is the use of this/ as the property of the second iterate. Basically, it's basically saying don't append anything more to the property reference, my parent's reference will do. ie: you're probably after myProperty[5][6] but the this/ is telling it to leave it at myProperty[5] never getting that next index. Truly multi-dimensional workings to the property constructors isn't an ability of BeanUtils as yet. It's interesting and may work its way into things in the future, but for now it's not there. So... what you'll have to do now is make the simplest of beans hold onto the second ArrayList and access it via a property so it has the full... firstList[5].secondList[6] ..nested property. The bean doesn't have to do anything special, just hold onto that array list so BeanUtils can get at the nested bean properly. Arron. On Wed, 2002-11-13 at 08:20, Louis Leung wrote: Hi all, In my action form there is a 2D collection, both used ArrayList. (i.e. An ArrayList whose elements are ArrayList also) I want to retrieve data (which are all String) from the 2nd layer of the 2D collection using nested:text ... tag so that it can populate the value back automatically. However, it is not working. Code in jsp : nested:form ... nested:iterate id=row property=A tr nested:iterate id=column property=this/ td % System.out.println(column); % nested:text property=this/ indexed=yes/ !-putting indexed=yes or not doesn't change the result abit-- /td /nested:iterate /tr /nested:iterate /nested:form Result (assume a 2X2 collection with elements A1, A2, B1, B2 in them already) 4 textboxes, the top 2 with [A1, A2] for both, and bottom 2 with [B1, B2] System.out prints out A1, A2, B1, B2 separately It seems like the 2nd iterate tag is indeed iterating thru the 2nd layer of the collection from the System.out statement. But the nested:text .../ tag is not retrieving each element of the 2nd layer collection. Rather, it is using the whole of the 2nd collection itself. Anyone has any idea why and possibly solution ? I would really like to use the nested:text .../ tag so that the values can be automatically populated back by Struts after the user input. Thanks in advance. Louis -- To unsubscribe, e-mail: mailto:struts-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:struts-user-help;jakarta.apache.org
RE: 2D Collection and nested:iterate
Thanks for the reply, appreciate it. From what I understand, I have to do something like : firstList --eachElementIs-- simpleBean --contains-- secondList In other words, wrap the 2nd list inside a bean. However, if that's the cast, I would imagine it will drag down the performance of our application by quite a bit due to Objects instantiation. (the 2D collection get used a lot and the collections are quite large). Is there anyway around it so that I can still use the original data structure ? Again, thanks for the input. :) -Original Message- From: Arron Bates [mailto:struts-user;keyboardmonkey.com] Sent: Tuesday, November 12, 2002 4:51 PM To: Struts Users Mailing List Subject: Re: 2D Collection and nested:iterate The problem is the use of this/ as the property of the second iterate. Basically, it's basically saying don't append anything more to the property reference, my parent's reference will do. ie: you're probably after myProperty[5][6] but the this/ is telling it to leave it at myProperty[5] never getting that next index. Truly multi-dimensional workings to the property constructors isn't an ability of BeanUtils as yet. It's interesting and may work its way into things in the future, but for now it's not there. So... what you'll have to do now is make the simplest of beans hold onto the second ArrayList and access it via a property so it has the full... firstList[5].secondList[6] ..nested property. The bean doesn't have to do anything special, just hold onto that array list so BeanUtils can get at the nested bean properly. Arron. On Wed, 2002-11-13 at 08:20, Louis Leung wrote: Hi all, In my action form there is a 2D collection, both used ArrayList. (i.e. An ArrayList whose elements are ArrayList also) I want to retrieve data (which are all String) from the 2nd layer of the 2D collection using nested:text ... tag so that it can populate the value back automatically. However, it is not working. Code in jsp : nested:form ... nested:iterate id=row property=A tr nested:iterate id=column property=this/ td % System.out.println(column); % nested:text property=this/ indexed=yes/ !-putting indexed=yes or not doesn't change the result abit-- /td /nested:iterate /tr /nested:iterate /nested:form Result (assume a 2X2 collection with elements A1, A2, B1, B2 in them already) 4 textboxes, the top 2 with [A1, A2] for both, and bottom 2 with [B1, B2] System.out prints out A1, A2, B1, B2 separately It seems like the 2nd iterate tag is indeed iterating thru the 2nd layer of the collection from the System.out statement. But the nested:text .../ tag is not retrieving each element of the 2nd layer collection. Rather, it is using the whole of the 2nd collection itself. Anyone has any idea why and possibly solution ? I would really like to use the nested:text .../ tag so that the values can be automatically populated back by Struts after the user input. Thanks in advance. Louis -- 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