commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Carman <ja...@carmanconsulting.com>
Subject Re: [beanutils] beanutils library cannot invoke the correct accessor
Date Mon, 07 Jun 2010 12:49:14 GMT
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.biz.etc@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.biz.etc@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.biz.etc@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


Mime
View raw message