commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james_strac...@yahoo.co.uk>
Subject [DynaBean] should converters be moved out of DynaBean into a BeanController?
Date Wed, 02 Jan 2002 17:38:33 GMT
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:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message