Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 25351 invoked from network); 25 Feb 2003 11:37:03 -0000 Received: from ip187.bb168.pacific.net.hk (HELO mail.pdsky.com) (202.64.168.187) by daedalus.apache.org with SMTP; 25 Feb 2003 11:37:03 -0000 Received: from mma ([192.168.0.180]) by mail.pdsky.com (Lotus Domino Release 6.0) with ESMTP id 2003022519365955-857 ; Tue, 25 Feb 2003 19:36:59 +0800 From: "Mingfai Ma" To: Subject: [beanutils] handle both simple object and array/list Date: Tue, 25 Feb 2003 19:37:03 +0800 Message-ID: MIME-Version: 1.0 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-MIMETrack: Itemize by SMTP Server on blacklotus/pdsky(Release 6.0|September 26, 2002) at 02/25/2003 07:36:59 PM, Serialize by Router on blacklotus/pdsky(Release 6.0|September 26, 2002) at 02/25/2003 07:37:00 PM, Serialize complete at 02/25/2003 07:37:00 PM Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N hi, I want to perform a "set" to JavaBean property without knowing whether it is a simple object or an array/list of objects. e.g. if the property is a String, then it calls setSimpleProperty, but if the property is a String[], then it calls setIndexedProperty. Does the PropertyUtils intelligent enough to do this task? which method should I use? if not, am I correct that, in the current PropertyUtils, the way to achieve my objective is to use getPropertyType, and then call two different set methods? do you think this is a useful addition to BeanUtils? (or am I too lazy to wish this feature! :-) ) a test case as example is given at the bottom. Regards, mingfai Example for illustrating the case: Bean ---- public class MyBean{ private String[] myString1; private String myString2; //getters & setters here } Application ----------- ... public void testMyBeanArrayMethod(){ MyBean myBean = new MyBean(); String strTest = "HELLO WORLD"; PropertyUtils.setSIMPLEorARRAYProperty( myBean, "myString1", strTest); //add one more item to the array String result = PropertyUtils.getSIMPLEorARRAYProperty( myBean, "myString1"); //get from the last item assertEquals( strTest, result); } public void testMyBeanSimpleMethod(){ MyBean myBean = new MyBean(); String strTest = "HELLO WORLD"; PropertyUtils.setSIMPLEorARRAYProperty( myBean, "myString2", strTest); //simple setProperty String result = PropertyUtils.getSIMPLEorARRAYProperty( myBean, "myString2"); //simple getProperty assertEquals( strTest, result); }