Re: Indexed Properties and Population
David says: One implementation that should work based on your example as long as you are willing to create a child factory is in the commons collection package and is ListUtils.lazyList, which takes a List and factory. I have used this as well, in combination with the nested tag library. We have a page that displays and updates a List of Value Objects where each have two internal Lists of Value Objects. The structure of value objects are sent to me from the back end as such: CustomerList CustomerVo 1 creditVo1 invoiceVo1 creditVo2 invoiceVo2 . . CustomerVo2 creditVo1 invoiceVo1 creditVo2 invoiceVo2 . . I would be curious to know this would done without the nested tags and lazy list. David Morris [EMAIL PROTECTED] on 01/16/2003 03:50:10 PM Please respond to Struts Users Mailing List [EMAIL PROTECTED] To:[EMAIL PROTECTED] cc: Subject:Re: Indexed Properties and Population Matt, You really don't need to know how many there are, just create them on demand. You can intercept gets and auto-extend the underlying Collection. One implementation that should work based on your example as long as you are willing to create a child factory is in the commons collection package and is ListUtils.lazyList, which takes a List and factory. David Morris [EMAIL PROTECTED] 01/16/03 02:31PM I have an ArrayList on a form... let's call the form Parent and the ArrayList Children. If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } Then saving my form results in a NPE for BeanUtils.copyProperties. If I create a whole bunch of objects in the ArrayList in the constructor - I avoid this problem: public ParentForm () { children = new ArrayList(100); for (int i=0; i 100; i++) { children.add(new ChildForm()); } But I'm guessing that this fits better into the reset(mapping, request) method of my form. My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? Thanks, Matt -- 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: Indexed Properties and Population
Here's how I did it: On my Form: public ArrayList getKids() { returns kids; } public void setKids(ArrayList kids) { this.kids = kids; } public int getKidsSize() { return kids.size(); } In my JSP: nested:iterate property=kids ... nested:text property=name/ ... /nested:iterate html:hidden property=kidsSize/ On my form (relevant for saving) public void reset(ActionMapping mapping, HttpServletRequest request) { // make the kids ArrayList the proper size and populate with // empty objects int kidsSize = Integer.parseInt(request.getParameter(kidsSize)); kids = new ArrayList(kidsSize); for (int i=0; i kidsSize; i++) { kids.add(new KidForm()); } } This seems to work great for me. Any other suggestions/methods are encouraged ;) Is it lunchtime (beertime) yet? HTH, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, January 17, 2003 6:52 AM To: Struts Users Mailing List Subject: Re: Indexed Properties and Population David says: One implementation that should work based on your example as long as you are willing to create a child factory is in the commons collection package and is ListUtils.lazyList, which takes a List and factory. I have used this as well, in combination with the nested tag library. We have a page that displays and updates a List of Value Objects where each have two internal Lists of Value Objects. The structure of value objects are sent to me from the back end as such: CustomerList CustomerVo 1 creditVo1 invoiceVo1 creditVo2 invoiceVo2 . . CustomerVo2 creditVo1 invoiceVo1 creditVo2 invoiceVo2 . . I would be curious to know this would done without the nested tags and lazy list. David Morris [EMAIL PROTECTED] on 01/16/2003 03:50:10 PM Please respond to Struts Users Mailing List [EMAIL PROTECTED] To:[EMAIL PROTECTED] cc: Subject:Re: Indexed Properties and Population Matt, You really don't need to know how many there are, just create them on demand. You can intercept gets and auto-extend the underlying Collection. One implementation that should work based on your example as long as you are willing to create a child factory is in the commons collection package and is ListUtils.lazyList, which takes a List and factory. David Morris [EMAIL PROTECTED] 01/16/03 02:31PM I have an ArrayList on a form... let's call the form Parent and the ArrayList Children. If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } Then saving my form results in a NPE for BeanUtils.copyProperties. If I create a whole bunch of objects in the ArrayList in the constructor - I avoid this problem: public ParentForm () { children = new ArrayList(100); for (int i=0; i 100; i++) { children.add(new ChildForm()); } But I'm guessing that this fits better into the reset(mapping, request) method of my form. My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? Thanks, Matt -- 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] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Indexed Properties and Population
I have an ArrayList on a form... let's call the form Parent and the ArrayList Children. If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } Then saving my form results in a NPE for BeanUtils.copyProperties. If I create a whole bunch of objects in the ArrayList in the constructor - I avoid this problem: public ParentForm () { children = new ArrayList(100); for (int i=0; i 100; i++) { children.add(new ChildForm()); } But I'm guessing that this fits better into the reset(mapping, request) method of my form. My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? Thanks, Matt -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Indexed Properties and Population
Matt, You really don't need to know how many there are, just create them on demand. You can intercept gets and auto-extend the underlying Collection. One implementation that should work based on your example as long as you are willing to create a child factory is in the commons collection package and is ListUtils.lazyList, which takes a List and factory. David Morris [EMAIL PROTECTED] 01/16/03 02:31PM I have an ArrayList on a form... let's call the form Parent and the ArrayList Children. If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } Then saving my form results in a NPE for BeanUtils.copyProperties. If I create a whole bunch of objects in the ArrayList in the constructor - I avoid this problem: public ParentForm () { children = new ArrayList(100); for (int i=0; i 100; i++) { children.add(new ChildForm()); } But I'm guessing that this fits better into the reset(mapping, request) method of my form. My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? Thanks, Matt -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Indexed Properties and Population
int elements = children.size() ? Where are you defining this method? -Original Message- From: Raible, Matt [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 16, 2003 4:31 PM If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Indexed Properties and Population
Just make sure you've got a way to cap the max number you auto-create... Quoting David Morris [EMAIL PROTECTED]: Matt, You really don't need to know how many there are, just create them on demand. You can intercept gets and auto-extend the underlying Collection. One implementation that should work based on your example as long as you are willing to create a child factory is in the commons collection package and is ListUtils.lazyList, which takes a List and factory. David Morris [EMAIL PROTECTED] 01/16/03 02:31PM I have an ArrayList on a form... let's call the form Parent and the ArrayList Children. If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } Then saving my form results in a NPE for BeanUtils.copyProperties. If I create a whole bunch of objects in the ArrayList in the constructor - I avoid this problem: public ParentForm () { children = new ArrayList(100); for (int i=0; i 100; i++) { children.add(new ChildForm()); } But I'm guessing that this fits better into the reset(mapping, request) method of my form. My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? Thanks, Matt -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- Kris Schneider mailto:[EMAIL PROTECTED] D.O.Tech http://www.dotech.com/ -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Indexed Properties and Population
I think what I'll do is to create a new method called getChildrenSize() that does what Mark suggests below - then I'll put this as a hidden field on my form. Since all my form's contents are dumped into a JSP (and gone), I've lost the size of the children - unless I save it as a hidden field, or count them in my nested:iterate tag. So then in my reset method on the form, I can create x number of children and do set(index, form). Thanks, Matt -Original Message- From: Mark Galbreath [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 16, 2003 2:57 PM To: 'Struts Users Mailing List' Subject: RE: Indexed Properties and Population int elements = children.size() ? Where are you defining this method? -Original Message- From: Raible, Matt [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 16, 2003 4:31 PM If I have: private ArrayList children; public void setChildren(int index, ChildForm childForm) { this.children.set(index, childForm); } My question is - how do I determine how many there are? Is there something in the request this this information - or should I set a hidden field with the number of children? -- 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]