Trent, Thanks but I was not overloading originally... I was using a getListValues & getListValue. I know this is not best practice, it is hard to see the difference, this code is more a derivative of trying to get it to work than it is in a final state.
Any other pointers would be welcomed. Thanks -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, May 13, 2004 8:16 PM To: Jakarta Commons Users List Subject: Re: Question: BeanUtils.copyProperty(Object bean, String name, Object value) G'day Bob, I think I see what your problem is. You have overloaded the ListValue property getters and setters. This is not supported in BeanUtils. Instead you should structure your class like this: public class IndexedBean { private List items; public IndexedBean() { this.items = new ArrayList(); } // simple getter and setter for list - these are only necessary if you // plan on copying the entire bean using BeanUtils.copyProperties(src, dest) public List getItems() { return this.items; } public void setItems(List items) { this.items = items; } // indexed getter and setter - different name - these methods are used by // BeanUtils.copyProperty(obj, name, value) so that it can determine what // converter to apply to the value nominated so that it fits the indexed property public Object getItemValue(int index) { return getItems().get(index); } public void setItemValue(int index, Object object) { getItems().add(index, object); } } Call BeanUtils.copyProperty() like you had before, ensuring that you use the "itemValue" property, not the "items" property: BeanUtils.copyProperty(toBean, "itemValue" + "[" + i + "]", Array.get(indexedObject, i)); Hope this helps! Cheers, Trent McClenahan Enterprise Web Services Phone: (02) 9466 7763 Email: [EMAIL PROTECTED] |---------+----------------------------> | | "Butash, Bob" | | | <[EMAIL PROTECTED]| | | om> | | | | | | 14/05/2004 00:02 | | | Please respond to| | | "Jakarta Commons | | | Users List" | | | | |---------+----------------------------> >--------------------------------------------------------------------------- ----------------------------------------------------| | | | To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]> | | cc: | | Subject: Question: BeanUtils.copyProperty(Object bean, String name, Object value) | >--------------------------------------------------------------------------- ----------------------------------------------------| Looking for help, I'm trying to copy a property from an indexed value to an indexed value. The snippet of code that I'm trying to do this with is: BeanUtils.copyProperty(toBean, fieldName + "[" + i + "]", Array.get(indexedObject, i)); Now looking at the JavaDoc I do see the warning: Does not support destination properties that are indexed, but only an indexed setter (as opposed to an array setter) is available. This warning is not clear to me, not sure what they are trying to say. I do notice in the parameter description it states that the name Property name (can be nested/indexed/mapped/combo). I'm not getting an error, the property is just skipped, the info in the log is: copyProperty([EMAIL PROTECTED] 3c, listValue[0], 1) DEBUG [main] (BeanUtils.java:407) - target type for property 'listValue' is null, so skipping ths setter I have the following accessors for the bean in question: private List listValues; public List getListValues() { if(listValues == null) { listValues = new ArrayList(); } return listValues; } public Object getListValue(int index) { return getListValues().get(index); } public void setListValues(List list) { listValues = list; } public void setListValue(int index, Object object) { getListValues().add(index, object); } Am I calling this method incorrectly for an indexed field? Does this method not support indexed fields at all??? Any help would be greatly appreciated....Thanks --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
