Re: Problem with BeanUtils.copyProperties()
Hi Ivan, I had a mistake in my value object. Be sure to check the following things: For every form field in your form there must be one and only one setter method with the same name. So if you have a form field called firstName there has to be a method setFirstName() in your Bean. The second thing (and I'm not sure if I'm correct here, but it resolved the problem for me) is, make sure the property of your bean is the same type like your form field. So again, if you have a form field firstName of type String there has to be a a property _firstName of type String in your Bean. Step through the the copyProperties() Method in your debugger and check on which property the exception is thrown. This is how i singled out my problem. Hope this helps. Good luck with the bug hunt! Patrick - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with BeanUtils.copyProperties()
Patrick, I had the same issue beforei am following a dirty to solve this problem :) But how did you solve this...kindly let me know Ivan -Original Message- From: Patrick Scheuerer [mailto:[EMAIL PROTECTED] Sent: Friday, January 02, 2004 12:13 PM To: Struts Users Mailing List Subject: Re: Problem with BeanUtils.copyProperties() and in contrary to my earlier problem, there's no other method with the same method name... Patrick Scheuerer wrote: > Argh! I'm about to loose my sanity over this... > > The problem with the String[] is now working but there's a new one of > course :-( > > For some reason BeanUtils.copyProperties() doesn't call a setter method > in the destination bean. > > Here's the definition of the form field in struts-config.xml > > type="java.lang.String"/> > > In the destination bean there's the corresponding setter > method: > public void setKeywords(String keywords) { > ... > } > > For some reason copyProperties() doesn't call my setter method. If I > step through copyProperties() in the debugger I get until > >for (int i = 0; i < origDescriptors.length; i++) { > .. > } else { > --> if (isWriteable(dest, name)) { > Object value = ((DynaBean) orig).get(name); > PropertyUtils.setSimpleProperty(dest, name, value); > } > } > > If I step over the if statement the following block of code is not being > executed. Why is this property not writeable??? > > At runtime the property in question in origDescriptors has the value: > > DynaProperty[name=keywords,type=class java.lang.String] > > Why is the setKeywords(String keywords) method not called on my dest > bean??? > > Can somebody please help me out here? What am I doing wrong? > > Thanks a lot, > Patrick > > > - > 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]
Re: Problem with BeanUtils.copyProperties()
Quoting Patrick Scheuerer <[EMAIL PROTECTED]>: > If there are multiple methods with the same name, shouldn't copyProperties() > pick the one with the same method signature as in the source bean??? In my > opinion this would at least be a desirable default behavior No, it shouldn't. BeanUtils uses the standard JavaBeans introspection logic of the JDK to determine what the legal property names are, and what the getter and setter method names are (the default is getFoo and setFoo, but that can be changed). If you have two setters with the same name (but a different parameter type), then -- by definition -- this is not a JavaBeans property so it will be ignored by BeanUtils. See the JavaBeans Specification for more information: http://java.sun.com/products/javabeans/reference/api/index.html > > Patrick > Craig McClanahan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with BeanUtils.copyProperties()
and in contrary to my earlier problem, there's no other method with the same method name... Patrick Scheuerer wrote: Argh! I'm about to loose my sanity over this... The problem with the String[] is now working but there's a new one of course :-( For some reason BeanUtils.copyProperties() doesn't call a setter method in the destination bean. Here's the definition of the form field in struts-config.xml type="java.lang.String"/> In the destination bean there's the corresponding setter method: public void setKeywords(String keywords) { ... } For some reason copyProperties() doesn't call my setter method. If I step through copyProperties() in the debugger I get until for (int i = 0; i < origDescriptors.length; i++) { .. } else { --> if (isWriteable(dest, name)) { Object value = ((DynaBean) orig).get(name); PropertyUtils.setSimpleProperty(dest, name, value); } } If I step over the if statement the following block of code is not being executed. Why is this property not writeable??? At runtime the property in question in origDescriptors has the value: DynaProperty[name=keywords,type=class java.lang.String] Why is the setKeywords(String keywords) method not called on my dest bean??? Can somebody please help me out here? What am I doing wrong? Thanks a lot, Patrick - 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]
Re: Problem with BeanUtils.copyProperties()
Argh! I'm about to loose my sanity over this... The problem with the String[] is now working but there's a new one of course :-( For some reason BeanUtils.copyProperties() doesn't call a setter method in the destination bean. Here's the definition of the form field in struts-config.xml In the destination bean there's the corresponding setter method: public void setKeywords(String keywords) { ... } For some reason copyProperties() doesn't call my setter method. If I step through copyProperties() in the debugger I get until for (int i = 0; i < origDescriptors.length; i++) { .. } else { --> if (isWriteable(dest, name)) { Object value = ((DynaBean) orig).get(name); PropertyUtils.setSimpleProperty(dest, name, value); } } If I step over the if statement the following block of code is not being executed. Why is this property not writeable??? At runtime the property in question in origDescriptors has the value: DynaProperty[name=keywords,type=class java.lang.String] Why is the setKeywords(String keywords) method not called on my dest bean??? Can somebody please help me out here? What am I doing wrong? Thanks a lot, Patrick - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with BeanUtils.copyProperties()
I think the javabean spec doesn't allow multiple setters for a single property. If I'm right, you cannot have two setXXX method with different parameters types, as beanutils just looks for a method named "setXXX" without using parameter types. Nico. > Ivan De La Pena wrote: > > Hope this helps : > Thanks Ivan, It did help :-). > > The problem I had was a bit strange: in my business object a had a method > setSomeProperty(String[] data) and a method setSomeProperty(Vector data). > copyProperties() called setSomeProperty(Vector data) on my business bean > although the method signature of the source bean has the first method signature > (witch a String[]). > If there are multiple methods with the same name, shouldn't copyProperties() > pick the one with the same method signature as in the source bean??? In my > opinion this would at least be a desirable default behavior > > Has anybody else experienced this problem? > > Patrick > > > > - > 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]
Re: Problem with BeanUtils.copyProperties()
Ivan De La Pena wrote: Hope this helps : Thanks Ivan, It did help :-). The problem I had was a bit strange: in my business object a had a method setSomeProperty(String[] data) and a method setSomeProperty(Vector data). copyProperties() called setSomeProperty(Vector data) on my business bean although the method signature of the source bean has the first method signature (witch a String[]). If there are multiple methods with the same name, shouldn't copyProperties() pick the one with the same method signature as in the source bean??? In my opinion this would at least be a desirable default behavior Has anybody else experienced this problem? Patrick - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with BeanUtils.copyProperties()
Hope this helps : public class Bean { private String[] array; public String[] getArray() { return array; } public void setArray(String[] array) { this.array = array; } } import org.apache.commons.beanutils.PropertyUtils; import java.util.HashMap ; public class Test2 { public static void main(String[] args) throws Exception{ Bean bean = new Bean(); HashMap mp = new HashMap(); mp.put("array",new String[]{"1","2","3"}); bean.setArray(new String[]{"1","2","3"}); Bean bean2 = new Bean(); Bean bean3 = new Bean(); PropertyUtils.copyProperties(bean2, bean); System.out.println(bean2.getArray()); PropertyUtils.copyProperties(bean3, mp); System.out.println(bean3.getArray()); } } Ivan -Original Message- From: Patrick Scheuerer [mailto:[EMAIL PROTECTED] Sent: Thursday, January 01, 2004 11:48 PM To: Struts Users List Subject: Problem with BeanUtils.copyProperties() Hi, Is it not possible to copy a String[] using BeanUtils.copyProperties()? My DynaValidatorForm has a field property like: My Business Bean has the following method: public void setSomeProperty(String[] data){ } Every time the copyProperty() method is called it throws the following exception: java.lang.IllegalArgumentException: argument type mismatch Can somebody help me out? Thanks! Patrick - 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]
Problem with BeanUtils.copyProperties()
Hi, Is it not possible to copy a String[] using BeanUtils.copyProperties()? My DynaValidatorForm has a field property like: My Business Bean has the following method: public void setSomeProperty(String[] data){ } Every time the copyProperty() method is called it throws the following exception: java.lang.IllegalArgumentException: argument type mismatch Can somebody help me out? Thanks! Patrick - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]