Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 94974 invoked from network); 2 Jan 2002 17:41:42 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Jan 2002 17:41:42 -0000 Received: (qmail 539 invoked by uid 97); 2 Jan 2002 17:41:39 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 523 invoked by uid 97); 2 Jan 2002 17:41:39 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 512 invoked from network); 2 Jan 2002 17:41:38 -0000 Message-ID: <04e401c193b4$4d9c4d90$9865fea9@spiritsoft.com> From: "James Strachan" To: "Jakarta Commons Developers" Subject: [DynaBean] should converters be moved out of DynaBean into a BeanController? Date: Wed, 2 Jan 2002 17:38:33 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Recent discussions of Converters and Validators in DynaBeans got me thinking. Should a DynaBean have this kind of logic attached to it, understanding how to convert to/from Strings and perform validation? Or should this be done at a level above? If DynaBeans are meant to be functionally similar to regular JavaBeans but are just dynamic (in that their properties can be defined at runtime without the need for code generation), then maybe the Converter/Validator stuff should be done by a seperate BeanController - then it could be equally well applied to real JavaBeans as to DynaBeans. So maybe we need a default BeanConverter that would work across Java Beans and DynaBeans to allow conversion & validation rules to be attached to bean properties with clever defaults (so things Just Work without any coding) but allowing customizations. // bean could be a DynaBean or a real Java Bean OrderBean bean = new OrderBean(); BeanController controller = new BeanController( bean, Locale.US ); // add some optional custom constraints & converters controller.addConstraint( "amount", new PositiveNumberConstraint() ); controller.addConstraint( "productCode", new EnumConstraint( validProductCodes ) ); // uses custom constraint checking, validation etc when setting values from strings. controller.set( "amount", "10000" ); // uses default date conversions controller.set( "date", "2/1/2" ); // after normalisation String amount = controller.get( "amount" ); String date = controller.get( "date" ); Then the BeanController could be used with (say) HttpServletRequests to get/set properties as Strings to/from beans. Ditto for Swing with JTextField & JTextArea etc. The nice thing about this direction is that different conversion & validation rules can be used in different circumstances; they are seperate from the 'business domain' objects. Also the BeanController can then store all the various context information, like Locale and Timezone and maybe security & user information. Disclaimer: Its a while since I looked at Struts; this BeanController idea might be straying into the domain of Struts as its similar to a front-controller, so appologies if I've strayed off the DynaBeans discussion radar. James _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: For additional commands, e-mail: