You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Dimitris Tsitses <4....@gmail.com> on 2010/06/06 04:02:59 UTC

[beanutils] beanutils library cannot invoke the correct accessor

Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.

I have a simple bean:


public class MyBean {
	private ClassTypeA myProperty;

	public void setMyProperty(ClassTypeA anObj) {
		this.myProperty = anObj;
	}
	public void setMyProperty(ClassTypeB anObj) {
		this.myProperty = Converter.convertBtoA(anObj);
	}

}

If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);


However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -

I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.

Many thanks
Dimitris

Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Niall Pemberton <ni...@gmail.com>.
On Sun, Jun 6, 2010 at 3:02 AM, Dimitris Tsitses <4....@gmail.com> wrote:
> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>
> I have a simple bean:
>
>
> public class MyBean {
>        private ClassTypeA myProperty;
>
>        public void setMyProperty(ClassTypeA anObj) {
>                this.myProperty = anObj;
>        }
>        public void setMyProperty(ClassTypeB anObj) {
>                this.myProperty = Converter.convertBtoA(anObj);
>        }
>
> }

The way to do this in BeanUtils is to get rid of your overloaded
setter for ClassTypeB and register a converter with Beanutils.
Something like...

    ClassTypeAConverter converter = new ClassTypeAConverter();
    ConvertUtils.register(converter,  ClassTypeA.class);

That way when you use BeanUtils.setProperty() it will call the
converter to convert the ClassTypeB to ClassTypeA.

Niall

> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>
>
> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>
> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>
> Many thanks
> Dimitris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Niall Pemberton <ni...@gmail.com>.
On Sun, Jun 6, 2010 at 5:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.

Well you're wrong about this - if you go an read section "8.3 Design
Patterns for Properties" of the Java Bean Specification you will see
it specified a *pair" (i.e. getter & setter) of accessor methods for
properties.

http://java.sun.com/javase/technologies/desktop/javabeans/docs/spec.html

Niall

> On 2010-06-06, at 5:50 AM, James Carman wrote:
>
>> That violates the JavaBeans specification.  "myProperty" is supposed
>> to be of one type only.
>>
>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>
>>> I have a simple bean:
>>>
>>>
>>> public class MyBean {
>>>        private ClassTypeA myProperty;
>>>
>>>        public void setMyProperty(ClassTypeA anObj) {
>>>                this.myProperty = anObj;
>>>        }
>>>        public void setMyProperty(ClassTypeB anObj) {
>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>        }
>>>
>>> }
>>>
>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>
>>>
>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>
>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>
>>> Many thanks
>>> Dimitris
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
Or, you could possibly use MethodUtils to find the best matching setter method.

On Mon, Jun 7, 2010 at 2:53 AM, henrib <he...@apache.org> wrote:
>
> I gather you need to invoke get/set methods through signature introspection
> rather than JavaBean spec.
> I dont know if this is possible for you to use it but JEXL2 just does that
> (JexlEngine.{s,g}etProperterty).
> Hope this can help,
> Henri
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/beanutils-beanutils-library-cannot-invoke-the-correct-accessor-tp2244705p2245549.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by henrib <he...@apache.org>.
I gather you need to invoke get/set methods through signature introspection
rather than JavaBean spec.
I dont know if this is possible for you to use it but JEXL2 just does that
(JexlEngine.{s,g}etProperterty).
Hope this can help,
Henri
-- 
View this message in context: http://apache-commons.680414.n4.nabble.com/beanutils-beanutils-library-cannot-invoke-the-correct-accessor-tp2244705p2245549.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
Create a helper method of your own somewhere?

On Mon, Jun 7, 2010 at 5:28 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> Sorry, it appears that I didn't explain myself properly. What I mean is that BeanUtils.setProperty() expects to receive the property name (i.e., "customer"), whereas MethodUtils.invokeMethod() expects to receive the method name (i.e., "setCustomer"). So I'm wondering what is the best way to resolve a property name into a setter method name. At the moment I use the following:
>
> PropertyDescriptor aPropDescriptor  = PropertyUtils.getPropertyDescriptor(myBeanInstance, propName);
> String setterMethodName = PropertyUtils.getWriteMethod( aPropDescriptor).getName();
>
> So that gives me the setter method name which I can pass to MethodUtils.invokeMethod(). However, PropertyUtils.getPropertyDescriptor() returns null for the bean example below. That's because a setter that accepts an argument of type ClassTypeA is not defined in that bean. I suppose that's not a big deal, I was just wondering though if there is an alternative way to resolve a property name to the setter method name of that property, merely on a string processing basis instead of reflection. Of course doing the string processing manually is 2 lines of code, but was curious as to whether there is a standard utility method in beanutils library.
>
> Thanks
> Dimitris
>
>
> public class MyBean {
>       private ClassTypeA myProperty;
>
>       public void setMyProperty(ClassTypeB anObj) {
>               this.myProperty = Converter.convertBtoA(anObj);
>       }
>
> }
>
> On 2010-06-07, at 2:05 PM, James Carman wrote:
>
>> On Mon, Jun 7, 2010 at 1:05 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>> Hi James,
>>>
>>> actually replacing:
>>> BeanUtils.setProperty(myBeanInst, myProperty, instanceOfClassTypeX);
>>>
>>> with:
>>> MethodUtils.invokeMethod(myBeanInst, myPropertySetter, instanceOfClassTypeX);
>>>
>>> works like a dream, thanks for pointing out MethodUtils. I'm currently converting 'myProperty' to 'myPropertySetter' manually (i.e., "propertyName" -> "setPropertyName"). Is there a convenience method that I could use for the conversion?
>>>
>>
>> Any modern IDE should have a rename refactoring feature.  I'd use that
>> to rename properties/methods.  That also will change the places where
>> it is used.  Very helpful.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Dimitris Tsitses <4....@gmail.com>.
Sorry, it appears that I didn't explain myself properly. What I mean is that BeanUtils.setProperty() expects to receive the property name (i.e., "customer"), whereas MethodUtils.invokeMethod() expects to receive the method name (i.e., "setCustomer"). So I'm wondering what is the best way to resolve a property name into a setter method name. At the moment I use the following:

PropertyDescriptor aPropDescriptor  = PropertyUtils.getPropertyDescriptor(myBeanInstance, propName);
String setterMethodName = PropertyUtils.getWriteMethod( aPropDescriptor).getName();

So that gives me the setter method name which I can pass to MethodUtils.invokeMethod(). However, PropertyUtils.getPropertyDescriptor() returns null for the bean example below. That's because a setter that accepts an argument of type ClassTypeA is not defined in that bean. I suppose that's not a big deal, I was just wondering though if there is an alternative way to resolve a property name to the setter method name of that property, merely on a string processing basis instead of reflection. Of course doing the string processing manually is 2 lines of code, but was curious as to whether there is a standard utility method in beanutils library.

Thanks
Dimitris


public class MyBean {
       private ClassTypeA myProperty;

       public void setMyProperty(ClassTypeB anObj) {
               this.myProperty = Converter.convertBtoA(anObj);
       }

}

On 2010-06-07, at 2:05 PM, James Carman wrote:

> On Mon, Jun 7, 2010 at 1:05 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>> Hi James,
>> 
>> actually replacing:
>> BeanUtils.setProperty(myBeanInst, myProperty, instanceOfClassTypeX);
>> 
>> with:
>> MethodUtils.invokeMethod(myBeanInst, myPropertySetter, instanceOfClassTypeX);
>> 
>> works like a dream, thanks for pointing out MethodUtils. I'm currently converting 'myProperty' to 'myPropertySetter' manually (i.e., "propertyName" -> "setPropertyName"). Is there a convenience method that I could use for the conversion?
>> 
> 
> Any modern IDE should have a rename refactoring feature.  I'd use that
> to rename properties/methods.  That also will change the places where
> it is used.  Very helpful.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
On Mon, Jun 7, 2010 at 1:05 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> Hi James,
>
> actually replacing:
> BeanUtils.setProperty(myBeanInst, myProperty, instanceOfClassTypeX);
>
> with:
> MethodUtils.invokeMethod(myBeanInst, myPropertySetter, instanceOfClassTypeX);
>
> works like a dream, thanks for pointing out MethodUtils. I'm currently converting 'myProperty' to 'myPropertySetter' manually (i.e., "propertyName" -> "setPropertyName"). Is there a convenience method that I could use for the conversion?
>

Any modern IDE should have a rename refactoring feature.  I'd use that
to rename properties/methods.  That also will change the places where
it is used.  Very helpful.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Dimitris Tsitses <4....@gmail.com>.
Hi James,

actually replacing:
BeanUtils.setProperty(myBeanInst, myProperty, instanceOfClassTypeX);

with:
MethodUtils.invokeMethod(myBeanInst, myPropertySetter, instanceOfClassTypeX);

works like a dream, thanks for pointing out MethodUtils. I'm currently converting 'myProperty' to 'myPropertySetter' manually (i.e., "propertyName" -> "setPropertyName"). Is there a convenience method that I could use for the conversion?

Thanks


On 2010-06-07, at 9:40 AM, James Carman wrote:

> No, you wouldn't have the fields, just the methods that do the
> conversion to store/retrieve the values from the one, main, field.
> 
> Also, I wouldn't consider this a "lack of basic functionality" on the
> part of BeanUtils (*many* folks use BeanUtils in their projects and
> haven't complained that this is a missing feature).  The BeanUtils
> library is based on the JavaBeans specification.  In your case, how
> would BeanUtils know how to process your API?  Would it be a
> read/write property of type ClassTypeA?  Would it be a read-only
> property of type ClassTypeB?
> 
> What you could do here is instead of using your own methods to convert
> the values, you can register a converter for ClassTypeA that allows
> you to convert from different types.
> 
> public class ClassTypeAConverter implements Converter
> {
>  public Object convert(Class type, Object value)
>  {
>    if(type instanceof ClassTypeB)
>    {
>      ...
>    }
>  }
> }
> 
> final ConvertUtilsBean convertUtils = new ConvertUtilsBean();
> convertUtils.register(new ClassTypeAConverter(),ClassTypeA.class);
> final BeanUtilsBean beanUtils = new BeanUtilsBean(convertUtils);
> ...
> beanUtils.setProperty(myBean, "myProperty", myClassTypeBObject);
> 
> 
> On Mon, Jun 7, 2010 at 12:18 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>> Hi James, thanks for keeping up with my questions.
>> 
>> So, you mean end up with something like this: ?
>> 
>> public class MyBean {
>>       private ClassTypeA myProperty;
>>       private ClassTypeB myPropertyAsB;
>>       private ClassTypeC myPropertyAsC;
>>       private ClassTypeD myPropertyAsD;
>>        .
>>        .
>> 
>>       public void setMyProperty(ClassTypeA anObj) {
>>               this.myProperty = anObj;
>>       }
>>       public void setMyPropertyAsB(ClassTypeB anObj) {
>>               this.myProperty = Converter.convertBtoA(anObj);
>>       }
>>        .
>>        .
>>        .
>> }
>> 
>> Isn't this hacky as hell, just to compensate for beanutils' lack of basic functionality (i.e., method overloading)? That looks really messy in my opinion, imagine doing that for a number of properties in a few beans. I honestly don't understand why this functionality is missing from beanutils. Anyhow, even if I wanted to do that, I could not in my use case. It's a very dynamic environment where property names are computed automatically based on mappings or field names in a DB. So I couldn't have multiple 'technical' property names for the same 'logical' property without butchering an otherwise very elegant design. I'd rather enhance the beanutils library instead. So the question still stands, how would I go about it?
>> 
>> Henri, thanks a lot for the tip about JEXL2, I will look into it and see if it's less work to replace beanutils with that library, instead of enhancing the beanutils library.
>> 
>> 
>> 
>> On 2010-06-07, at 5:49 AM, James Carman wrote:
>> 
>>> Why not have another "calculated" property ("myPropertyAsB") that can
>>> do the translation from ClassTypeB to/from ClassTypeA and store it
>>> into myProperty?  That way, you don't have to modify the library at
>>> all?
>>> 
>>> On Mon, Jun 7, 2010 at 12:04 AM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>> Ok. I need some help to hack the library, where do I start. I want to make it so that it checks the available setters against the objectType of the given argument, instead of assuming an argument of a specific type. Example:
>>>> 
>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeX);
>>>> 
>>>> Algo: is there a setMyProperty in myBeanInst, accepting an argument of type ClassTypeX?
>>>> YES: call it
>>>> NO: throw exception
>>>> 
>>>> Would appreciate it if someone could point me to the right direction for achieving the above.
>>>> 
>>>> Thanks
>>>> Dimitris
>>>> 
>>>> 
>>>> On 2010-06-06, at 8:24 PM, James Carman wrote:
>>>> 
>>>>> The property consists of the getter/setter, not some field.  So, the
>>>>> pair of matching setter/getter are what makes up the property.  The
>>>>> overloaded method isn't a setter for the property.
>>>>> 
>>>>> On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>>> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>>>>>> 
>>>>>> 
>>>>>> On 2010-06-06, at 5:50 AM, James Carman wrote:
>>>>>> 
>>>>>>> That violates the JavaBeans specification.  "myProperty" is supposed
>>>>>>> to be of one type only.
>>>>>>> 
>>>>>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>>>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>>>>>> 
>>>>>>>> I have a simple bean:
>>>>>>>> 
>>>>>>>> 
>>>>>>>> public class MyBean {
>>>>>>>>        private ClassTypeA myProperty;
>>>>>>>> 
>>>>>>>>        public void setMyProperty(ClassTypeA anObj) {
>>>>>>>>                this.myProperty = anObj;
>>>>>>>>        }
>>>>>>>>        public void setMyProperty(ClassTypeB anObj) {
>>>>>>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>>>>>>        }
>>>>>>>> 
>>>>>>>> }
>>>>>>>> 
>>>>>>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>>>>>> 
>>>>>>>> 
>>>>>>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>>>>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>>>>>> 
>>>>>>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>>>>>> 
>>>>>>>> Many thanks
>>>>>>>> Dimitris
>>>>>>> 
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>> 
>>>>>> 
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>> 
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
No, you wouldn't have the fields, just the methods that do the
conversion to store/retrieve the values from the one, main, field.

Also, I wouldn't consider this a "lack of basic functionality" on the
part of BeanUtils (*many* folks use BeanUtils in their projects and
haven't complained that this is a missing feature).  The BeanUtils
library is based on the JavaBeans specification.  In your case, how
would BeanUtils know how to process your API?  Would it be a
read/write property of type ClassTypeA?  Would it be a read-only
property of type ClassTypeB?

What you could do here is instead of using your own methods to convert
the values, you can register a converter for ClassTypeA that allows
you to convert from different types.

public class ClassTypeAConverter implements Converter
{
  public Object convert(Class type, Object value)
  {
    if(type instanceof ClassTypeB)
    {
      ...
    }
  }
}

final ConvertUtilsBean convertUtils = new ConvertUtilsBean();
convertUtils.register(new ClassTypeAConverter(),ClassTypeA.class);
final BeanUtilsBean beanUtils = new BeanUtilsBean(convertUtils);
...
beanUtils.setProperty(myBean, "myProperty", myClassTypeBObject);


On Mon, Jun 7, 2010 at 12:18 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> Hi James, thanks for keeping up with my questions.
>
> So, you mean end up with something like this: ?
>
> public class MyBean {
>       private ClassTypeA myProperty;
>       private ClassTypeB myPropertyAsB;
>       private ClassTypeC myPropertyAsC;
>       private ClassTypeD myPropertyAsD;
>        .
>        .
>
>       public void setMyProperty(ClassTypeA anObj) {
>               this.myProperty = anObj;
>       }
>       public void setMyPropertyAsB(ClassTypeB anObj) {
>               this.myProperty = Converter.convertBtoA(anObj);
>       }
>        .
>        .
>        .
> }
>
> Isn't this hacky as hell, just to compensate for beanutils' lack of basic functionality (i.e., method overloading)? That looks really messy in my opinion, imagine doing that for a number of properties in a few beans. I honestly don't understand why this functionality is missing from beanutils. Anyhow, even if I wanted to do that, I could not in my use case. It's a very dynamic environment where property names are computed automatically based on mappings or field names in a DB. So I couldn't have multiple 'technical' property names for the same 'logical' property without butchering an otherwise very elegant design. I'd rather enhance the beanutils library instead. So the question still stands, how would I go about it?
>
> Henri, thanks a lot for the tip about JEXL2, I will look into it and see if it's less work to replace beanutils with that library, instead of enhancing the beanutils library.
>
>
>
> On 2010-06-07, at 5:49 AM, James Carman wrote:
>
>> Why not have another "calculated" property ("myPropertyAsB") that can
>> do the translation from ClassTypeB to/from ClassTypeA and store it
>> into myProperty?  That way, you don't have to modify the library at
>> all?
>>
>> On Mon, Jun 7, 2010 at 12:04 AM, Dimitris Tsitses <4....@gmail.com> wrote:
>>> Ok. I need some help to hack the library, where do I start. I want to make it so that it checks the available setters against the objectType of the given argument, instead of assuming an argument of a specific type. Example:
>>>
>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeX);
>>>
>>> Algo: is there a setMyProperty in myBeanInst, accepting an argument of type ClassTypeX?
>>> YES: call it
>>> NO: throw exception
>>>
>>> Would appreciate it if someone could point me to the right direction for achieving the above.
>>>
>>> Thanks
>>> Dimitris
>>>
>>>
>>> On 2010-06-06, at 8:24 PM, James Carman wrote:
>>>
>>>> The property consists of the getter/setter, not some field.  So, the
>>>> pair of matching setter/getter are what makes up the property.  The
>>>> overloaded method isn't a setter for the property.
>>>>
>>>> On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>>>>>
>>>>>
>>>>> On 2010-06-06, at 5:50 AM, James Carman wrote:
>>>>>
>>>>>> That violates the JavaBeans specification.  "myProperty" is supposed
>>>>>> to be of one type only.
>>>>>>
>>>>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>>>>>
>>>>>>> I have a simple bean:
>>>>>>>
>>>>>>>
>>>>>>> public class MyBean {
>>>>>>>        private ClassTypeA myProperty;
>>>>>>>
>>>>>>>        public void setMyProperty(ClassTypeA anObj) {
>>>>>>>                this.myProperty = anObj;
>>>>>>>        }
>>>>>>>        public void setMyProperty(ClassTypeB anObj) {
>>>>>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>>>>>        }
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>>>>>
>>>>>>>
>>>>>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>>>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>>>>>
>>>>>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>>>>>
>>>>>>> Many thanks
>>>>>>> Dimitris
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Niall Pemberton <ni...@gmail.com>.
On Mon, Jun 7, 2010 at 5:18 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> Hi James, thanks for keeping up with my questions.
>
> So, you mean end up with something like this: ?
>
> public class MyBean {
>       private ClassTypeA myProperty;
>       private ClassTypeB myPropertyAsB;
>       private ClassTypeC myPropertyAsC;
>       private ClassTypeD myPropertyAsD;
>
>       public void setMyProperty(ClassTypeA anObj) {
>               this.myProperty = anObj;
>       }
>       public void setMyPropertyAsB(ClassTypeB anObj) {
>               this.myProperty = Converter.convertBtoA(anObj);
>       }
>        .
>        .
>        .
> }
>
> Isn't this hacky as hell, just to compensate for beanutils' lack of basic functionality (i.e., method overloading)? That looks really messy in my opinion, imagine doing that for a number of properties in a few beans. I honestly don't understand why this functionality is missing from beanutils. Anyhow, even if I wanted to do that, I could not in my use case. It's a very dynamic environment where property names are computed automatically based on mappings or field names in a DB. So I couldn't have multiple 'technical' property names for the same 'logical' property without butchering an otherwise very elegant design. I'd rather enhance the beanutils library instead. So the question still stands, how would I go about it?

Hacky as hell is you overloading the accessor methods and will cause
you problems when using your java beans with any technology that
relies on the JavaBean specification - not just BeanUtils. I would
really recommend you avoid doing this.

Niall


> Henri, thanks a lot for the tip about JEXL2, I will look into it and see if it's less work to replace beanutils with that library, instead of enhancing the beanutils library.
>
>
>
> On 2010-06-07, at 5:49 AM, James Carman wrote:
>
>> Why not have another "calculated" property ("myPropertyAsB") that can
>> do the translation from ClassTypeB to/from ClassTypeA and store it
>> into myProperty?  That way, you don't have to modify the library at
>> all?
>>
>> On Mon, Jun 7, 2010 at 12:04 AM, Dimitris Tsitses <4....@gmail.com> wrote:
>>> Ok. I need some help to hack the library, where do I start. I want to make it so that it checks the available setters against the objectType of the given argument, instead of assuming an argument of a specific type. Example:
>>>
>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeX);
>>>
>>> Algo: is there a setMyProperty in myBeanInst, accepting an argument of type ClassTypeX?
>>> YES: call it
>>> NO: throw exception
>>>
>>> Would appreciate it if someone could point me to the right direction for achieving the above.
>>>
>>> Thanks
>>> Dimitris
>>>
>>>
>>> On 2010-06-06, at 8:24 PM, James Carman wrote:
>>>
>>>> The property consists of the getter/setter, not some field.  So, the
>>>> pair of matching setter/getter are what makes up the property.  The
>>>> overloaded method isn't a setter for the property.
>>>>
>>>> On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>>>>>
>>>>>
>>>>> On 2010-06-06, at 5:50 AM, James Carman wrote:
>>>>>
>>>>>> That violates the JavaBeans specification.  "myProperty" is supposed
>>>>>> to be of one type only.
>>>>>>
>>>>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>>>>>
>>>>>>> I have a simple bean:
>>>>>>>
>>>>>>>
>>>>>>> public class MyBean {
>>>>>>>        private ClassTypeA myProperty;
>>>>>>>
>>>>>>>        public void setMyProperty(ClassTypeA anObj) {
>>>>>>>                this.myProperty = anObj;
>>>>>>>        }
>>>>>>>        public void setMyProperty(ClassTypeB anObj) {
>>>>>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>>>>>        }
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>>>>>
>>>>>>>
>>>>>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>>>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>>>>>
>>>>>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>>>>>
>>>>>>> Many thanks
>>>>>>> Dimitris
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Dimitris Tsitses <4....@gmail.com>.
Hi James, thanks for keeping up with my questions.

So, you mean end up with something like this: ?

public class MyBean {
       private ClassTypeA myProperty;
       private ClassTypeB myPropertyAsB;
       private ClassTypeC myPropertyAsC;
       private ClassTypeD myPropertyAsD;
	.
	.

       public void setMyProperty(ClassTypeA anObj) {
               this.myProperty = anObj;
       }
       public void setMyPropertyAsB(ClassTypeB anObj) {
               this.myProperty = Converter.convertBtoA(anObj);
       }
	.
	.
	.
}

Isn't this hacky as hell, just to compensate for beanutils' lack of basic functionality (i.e., method overloading)? That looks really messy in my opinion, imagine doing that for a number of properties in a few beans. I honestly don't understand why this functionality is missing from beanutils. Anyhow, even if I wanted to do that, I could not in my use case. It's a very dynamic environment where property names are computed automatically based on mappings or field names in a DB. So I couldn't have multiple 'technical' property names for the same 'logical' property without butchering an otherwise very elegant design. I'd rather enhance the beanutils library instead. So the question still stands, how would I go about it?

Henri, thanks a lot for the tip about JEXL2, I will look into it and see if it's less work to replace beanutils with that library, instead of enhancing the beanutils library.



On 2010-06-07, at 5:49 AM, James Carman wrote:

> Why not have another "calculated" property ("myPropertyAsB") that can
> do the translation from ClassTypeB to/from ClassTypeA and store it
> into myProperty?  That way, you don't have to modify the library at
> all?
> 
> On Mon, Jun 7, 2010 at 12:04 AM, Dimitris Tsitses <4....@gmail.com> wrote:
>> Ok. I need some help to hack the library, where do I start. I want to make it so that it checks the available setters against the objectType of the given argument, instead of assuming an argument of a specific type. Example:
>> 
>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeX);
>> 
>> Algo: is there a setMyProperty in myBeanInst, accepting an argument of type ClassTypeX?
>> YES: call it
>> NO: throw exception
>> 
>> Would appreciate it if someone could point me to the right direction for achieving the above.
>> 
>> Thanks
>> Dimitris
>> 
>> 
>> On 2010-06-06, at 8:24 PM, James Carman wrote:
>> 
>>> The property consists of the getter/setter, not some field.  So, the
>>> pair of matching setter/getter are what makes up the property.  The
>>> overloaded method isn't a setter for the property.
>>> 
>>> On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>>>> 
>>>> 
>>>> On 2010-06-06, at 5:50 AM, James Carman wrote:
>>>> 
>>>>> That violates the JavaBeans specification.  "myProperty" is supposed
>>>>> to be of one type only.
>>>>> 
>>>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>>>> 
>>>>>> I have a simple bean:
>>>>>> 
>>>>>> 
>>>>>> public class MyBean {
>>>>>>        private ClassTypeA myProperty;
>>>>>> 
>>>>>>        public void setMyProperty(ClassTypeA anObj) {
>>>>>>                this.myProperty = anObj;
>>>>>>        }
>>>>>>        public void setMyProperty(ClassTypeB anObj) {
>>>>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>>>>        }
>>>>>> 
>>>>>> }
>>>>>> 
>>>>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>>>> 
>>>>>> 
>>>>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>>>> 
>>>>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>>>> 
>>>>>> Many thanks
>>>>>> Dimitris
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>> 
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
Why not have another "calculated" property ("myPropertyAsB") that can
do the translation from ClassTypeB to/from ClassTypeA and store it
into myProperty?  That way, you don't have to modify the library at
all?

On Mon, Jun 7, 2010 at 12:04 AM, Dimitris Tsitses <4....@gmail.com> wrote:
> Ok. I need some help to hack the library, where do I start. I want to make it so that it checks the available setters against the objectType of the given argument, instead of assuming an argument of a specific type. Example:
>
> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeX);
>
> Algo: is there a setMyProperty in myBeanInst, accepting an argument of type ClassTypeX?
> YES: call it
> NO: throw exception
>
> Would appreciate it if someone could point me to the right direction for achieving the above.
>
> Thanks
> Dimitris
>
>
> On 2010-06-06, at 8:24 PM, James Carman wrote:
>
>> The property consists of the getter/setter, not some field.  So, the
>> pair of matching setter/getter are what makes up the property.  The
>> overloaded method isn't a setter for the property.
>>
>> On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>>>
>>>
>>> On 2010-06-06, at 5:50 AM, James Carman wrote:
>>>
>>>> That violates the JavaBeans specification.  "myProperty" is supposed
>>>> to be of one type only.
>>>>
>>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>>>
>>>>> I have a simple bean:
>>>>>
>>>>>
>>>>> public class MyBean {
>>>>>        private ClassTypeA myProperty;
>>>>>
>>>>>        public void setMyProperty(ClassTypeA anObj) {
>>>>>                this.myProperty = anObj;
>>>>>        }
>>>>>        public void setMyProperty(ClassTypeB anObj) {
>>>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>>>        }
>>>>>
>>>>> }
>>>>>
>>>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>>>
>>>>>
>>>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>>>
>>>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>>>
>>>>> Many thanks
>>>>> Dimitris
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Dimitris Tsitses <4....@gmail.com>.
Ok. I need some help to hack the library, where do I start. I want to make it so that it checks the available setters against the objectType of the given argument, instead of assuming an argument of a specific type. Example:

BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeX);

Algo: is there a setMyProperty in myBeanInst, accepting an argument of type ClassTypeX?
YES: call it
NO: throw exception

Would appreciate it if someone could point me to the right direction for achieving the above.

Thanks
Dimitris


On 2010-06-06, at 8:24 PM, James Carman wrote:

> The property consists of the getter/setter, not some field.  So, the
> pair of matching setter/getter are what makes up the property.  The
> overloaded method isn't a setter for the property.
> 
> On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>> 
>> 
>> On 2010-06-06, at 5:50 AM, James Carman wrote:
>> 
>>> That violates the JavaBeans specification.  "myProperty" is supposed
>>> to be of one type only.
>>> 
>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>> 
>>>> I have a simple bean:
>>>> 
>>>> 
>>>> public class MyBean {
>>>>        private ClassTypeA myProperty;
>>>> 
>>>>        public void setMyProperty(ClassTypeA anObj) {
>>>>                this.myProperty = anObj;
>>>>        }
>>>>        public void setMyProperty(ClassTypeB anObj) {
>>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>>        }
>>>> 
>>>> }
>>>> 
>>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>> 
>>>> 
>>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>> 
>>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>> 
>>>> Many thanks
>>>> Dimitris
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
The property consists of the getter/setter, not some field.  So, the
pair of matching setter/getter are what makes up the property.  The
overloaded method isn't a setter for the property.

On Sun, Jun 6, 2010 at 12:55 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness.
>
>
> On 2010-06-06, at 5:50 AM, James Carman wrote:
>
>> That violates the JavaBeans specification.  "myProperty" is supposed
>> to be of one type only.
>>
>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>>>
>>> I have a simple bean:
>>>
>>>
>>> public class MyBean {
>>>        private ClassTypeA myProperty;
>>>
>>>        public void setMyProperty(ClassTypeA anObj) {
>>>                this.myProperty = anObj;
>>>        }
>>>        public void setMyProperty(ClassTypeB anObj) {
>>>                this.myProperty = Converter.convertBtoA(anObj);
>>>        }
>>>
>>> }
>>>
>>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>>>
>>>
>>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>>>
>>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>>>
>>> Many thanks
>>> Dimitris
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by Dimitris Tsitses <4....@gmail.com>.
myProperty is of one type only. The overloaded setters are there only for convenience, i.e., to convert to the type of myProperty before setting it. I don't think the JavaBeans spec disallows that, if it did, that would mean that the JavaBeans spec undermines Java's spec! (i.e., do you like method overloading? Well, you can't use it here!). That would of course severally restrict JavaBeans usefulness. 


On 2010-06-06, at 5:50 AM, James Carman wrote:

> That violates the JavaBeans specification.  "myProperty" is supposed
> to be of one type only.
> 
> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
>> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>> 
>> I have a simple bean:
>> 
>> 
>> public class MyBean {
>>        private ClassTypeA myProperty;
>> 
>>        public void setMyProperty(ClassTypeA anObj) {
>>                this.myProperty = anObj;
>>        }
>>        public void setMyProperty(ClassTypeB anObj) {
>>                this.myProperty = Converter.convertBtoA(anObj);
>>        }
>> 
>> }
>> 
>> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>> 
>> 
>> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>> 
>> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>> 
>> Many thanks
>> Dimitris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [beanutils] beanutils library cannot invoke the correct accessor

Posted by James Carman <ja...@carmanconsulting.com>.
That violates the JavaBeans specification.  "myProperty" is supposed
to be of one type only.

On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4....@gmail.com> wrote:
> Hi all, I'm trying to do something really simple but I can't seem to figure it out, I hope someone can help.
>
> I have a simple bean:
>
>
> public class MyBean {
>        private ClassTypeA myProperty;
>
>        public void setMyProperty(ClassTypeA anObj) {
>                this.myProperty = anObj;
>        }
>        public void setMyProperty(ClassTypeB anObj) {
>                this.myProperty = Converter.convertBtoA(anObj);
>        }
>
> }
>
> If I invoke the setter by passing an instance of ClassTypeA, it works without a problem:
> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeA);
>
>
> However if I invoke the setter by passing an instance of ClassTypeB, I get an exception and the setter is never actually called:
> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassTypeB);
> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argument type mismatch -
>
> I can't believe it is not possible to do that, I'm sure I'm just missing something. Any help will be greatly appreciated.
>
> Many thanks
> Dimitris

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org