Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 66918 invoked from network); 10 Jun 2010 14:31:00 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Jun 2010 14:31:00 -0000 Received: (qmail 51012 invoked by uid 500); 10 Jun 2010 14:30:59 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 50918 invoked by uid 500); 10 Jun 2010 14:30:59 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 50910 invoked by uid 99); 10 Jun 2010 14:30:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 14:30:59 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of niall.pemberton@gmail.com designates 209.85.161.43 as permitted sender) Received: from [209.85.161.43] (HELO mail-fx0-f43.google.com) (209.85.161.43) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 14:30:51 +0000 Received: by fxm10 with SMTP id 10so218119fxm.30 for ; Thu, 10 Jun 2010 07:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=g75P8uk1icNNy9GeUR3UbbA8wcR3JMmleF+FAF489rk=; b=Hhh1vnN0owHRcExHQc6E2Kk+VFyTPG0YnzBgge3QPE+8cIWUMF/xeIL+vBLLe0Svn4 xiS5gMkrqx+IKTxGmTqUeuL0pwVsB7s1j9IQFszX10ust4VTPwY/lCT4VaYJDBWZUNro IfadL6+zPwxtTtAOyrxC02OzCiZdqzcfGcJQ4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=voIclnvGW89bM31OICetJjEieq0cW5UgWDQ/5O5x5noD0sHnBBUqpCqJk0DTObe+/r IqgilGF/wozyNjMaa70HMjCwlwGsGUTrOB3oUuvcH7jQzoC2P2vty/kMT8LayhEDoEC7 qwlWUM1Cm5Z6djQ+wBbeqHwh4wd9uS4Uzt2aI= MIME-Version: 1.0 Received: by 10.239.132.65 with SMTP id 1mr19629hbq.25.1276180230452; Thu, 10 Jun 2010 07:30:30 -0700 (PDT) Received: by 10.239.155.145 with HTTP; Thu, 10 Jun 2010 07:30:30 -0700 (PDT) In-Reply-To: References: <8D4AAECF-0F01-4496-B598-8D936FAA6F0C@gmail.com> <1C43548E-3165-4F11-91E3-8EC0BA2DF52F@gmail.com> <9DEAEC77-2E29-42D1-BAFD-C1594B481AD3@gmail.com> Date: Thu, 10 Jun 2010 15:30:30 +0100 Message-ID: Subject: Re: [beanutils] beanutils library cannot invoke the correct accessor From: Niall Pemberton To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Mon, Jun 7, 2010 at 5:18 PM, Dimitris Tsitses <4.biz.etc@gmail.com> wrot= e: > Hi James, thanks for keeping up with my questions. > > So, you mean end up with something like this: ? > > public class MyBean { > =A0 =A0 =A0 private ClassTypeA myProperty; > =A0 =A0 =A0 private ClassTypeB myPropertyAsB; > =A0 =A0 =A0 private ClassTypeC myPropertyAsC; > =A0 =A0 =A0 private ClassTypeD myPropertyAsD; > > =A0 =A0 =A0 public void setMyProperty(ClassTypeA anObj) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 this.myProperty =3D anObj; > =A0 =A0 =A0 } > =A0 =A0 =A0 public void setMyPropertyAsB(ClassTypeB anObj) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 this.myProperty =3D Converter.convertBtoA(anO= bj); > =A0 =A0 =A0 } > =A0 =A0 =A0 =A0. > =A0 =A0 =A0 =A0. > =A0 =A0 =A0 =A0. > } > > 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 op= inion, imagine doing that for a number of properties in a few beans. I hone= stly don't understand why this functionality is missing from beanutils. Any= how, even if I wanted to do that, I could not in my use case. It's a very d= ynamic environment where property names are computed automatically based on= mappings or field names in a DB. So I couldn't have multiple 'technical' p= roperty names for the same 'logical' property without butchering an otherwi= se very elegant design. I'd rather enhance the beanutils library instead. S= o 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 enhanc= ing 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? =A0That 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 m= ake it so that it checks the available setters against the objectType of th= e given argument, instead of assuming an argument of a specific type. Examp= le: >>> >>> 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 fo= r 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. =A0So, the >>>> pair of matching setter/getter are what makes up the property. =A0The >>>> 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 me= thod overloading? Well, you can't use it here!). That would of course sever= ally restrict JavaBeans usefulness. >>>>> >>>>> >>>>> On 2010-06-06, at 5:50 AM, James Carman wrote: >>>>> >>>>>> That violates the JavaBeans specification. =A0"myProperty" is suppos= ed >>>>>> to be of one type only. >>>>>> >>>>>> On Sat, Jun 5, 2010 at 10:02 PM, Dimitris Tsitses <4.biz.etc@gmail.c= om> wrote: >>>>>>> Hi all, I'm trying to do something really simple but I can't seem t= o figure it out, I hope someone can help. >>>>>>> >>>>>>> I have a simple bean: >>>>>>> >>>>>>> >>>>>>> public class MyBean { >>>>>>> =A0 =A0 =A0 =A0private ClassTypeA myProperty; >>>>>>> >>>>>>> =A0 =A0 =A0 =A0public void setMyProperty(ClassTypeA anObj) { >>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.myProperty =3D anObj; >>>>>>> =A0 =A0 =A0 =A0} >>>>>>> =A0 =A0 =A0 =A0public void setMyProperty(ClassTypeB anObj) { >>>>>>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.myProperty =3D Converter.conver= tBtoA(anObj); >>>>>>> =A0 =A0 =A0 =A0} >>>>>>> >>>>>>> } >>>>>>> >>>>>>> If I invoke the setter by passing an instance of ClassTypeA, it wor= ks without a problem: >>>>>>> BeanUtils.setProperty(myBeanInst, "myProperty", instanceOfClassType= A); >>>>>>> >>>>>>> >>>>>>> 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", instanceOfClassType= B); >>>>>>> java.lang.IllegalArgumentException: Cannot invoke.. la la la - argu= ment type mismatch - >>>>>>> >>>>>>> I can't believe it is not possible to do that, I'm sure I'm just mi= ssing 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