|
From: Chris W. <cwi...@op...> - 2004-03-05 15:37:11
|
Is there a way to permanantly (for the life of the current JVM instance) register a property editor for the BeanWrapper (BeanWrapperImpl) to use? I see it maintains a static map of 'defaultEditors' but it looks like custom editors have to be registered with each wrapper instance. Would it be possible to add a: static void registerCustomerEditor( Class c, PropertyEditor e ) or something similar that adds a custom editor to the default (or global) editors? Thanks, Chris -- Chris Winters (cwi...@op...) Senior Software Architect |
|
From: Alef A. <al...@jt...> - 2004-03-05 15:51:19
|
It's not possible to do this via a static on the BeanWrapper. It IS =
possible
however...
J=FCrgen added a CustomEditorConfigurer that you can use to do this. =
Just add
it to you app context and you're done.
<!-- taken from JavaDOC -->
<bean id=3D"customEditorConfigurer"
class=3D"org.springframework.beans.factory.config.CustomEditorConfigurer"=
>
<property name=3D"customEditors">
<map>
<entry key=3D"java.util.Date">
<bean class=3D"mypackage.MyCustomDateEditor"/>
</entry>
<entry key=3D"mypackage.MyObject">
<bean id=3D"myEditor" class=3D"mypackage.MObjectEditor">
<property name=3D"myParam"><value>myValue</value></property>
</bean>
</entry>
</map>
</property>
</bean>
If you're programmatically using the BeanFactory, you can add
propertyeditors using registerCustomEditor from the BeanFactory (or use =
a
BeanFactoryPostProcessor).
Alef
=09
> -----Original Message-----
> From: spr...@li...
> [mailto:spr...@li...] On =
Behalf
> Of Chris Winters
> Sent: Friday, March 05, 2004 4:17 PM
> To: Spring-Dev
> Subject: [Springframework-developer] "permanantly" registering =
property
> editor with BeanWrapper?
>=20
> Is there a way to permanantly (for the life of the current JVM
> instance) register a property editor for the BeanWrapper
> (BeanWrapperImpl) to use? I see it maintains a static map of
> 'defaultEditors' but it looks like custom editors have to be
> registered with each wrapper instance.
>=20
> Would it be possible to add a:
>=20
> static void registerCustomerEditor( Class c, PropertyEditor e )
>=20
> or something similar that adds a custom editor to the default (or
> global) editors?
>=20
> Thanks,
>=20
> Chris
>=20
> --
> Chris Winters (cwi...@op...)
> Senior Software Architect
>=20
>=20
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> =
administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli=
ck
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|
|
From: Chris W. <cwi...@op...> - 2004-03-05 16:18:29
|
Alef Arendsen wrote: > It's not possible to do this via a static on the BeanWrapper. It IS pos= sible > however... >=20 > J=FCrgen added a CustomEditorConfigurer that you can use to do this. Ju= st add > it to you app context and you're done. >=20 > <!-- taken from JavaDOC --> > <bean id=3D"customEditorConfigurer" > ... Excellent! That should work just fine. > If you're programmatically using the BeanFactory, you can add > propertyeditors using registerCustomEditor from the BeanFactory (or use= a > BeanFactoryPostProcessor). This is what I started doing, but if I instantiate a=20 BeanWrapperImpl myself the editors aren't available. (I'm just=20 using the BeanWrapper as a shortcut to do some property mapping=20 because it's so darned convenient.) Plus I'm not sure how to do this from an ApplicationContext vs. a=20 BeanFactory -- the registerCustomEditor() seems to be implemented=20 in AbstractBeanFactory which doesn't seem to be a parent of any=20 ApplicationContext class. (I'm a little hazy on the relationships=20 among the objects at this level tho.) Thanks! Chris --=20 Chris Winters (cwi...@op...) Senior Software Architect |
|
From: Alef A. <al...@jt...> - 2004-03-05 16:33:45
|
Oops, I guess (no I don't guess, I know for sure ;-) manually = instantiating a BeanWrapperImpl won't give you the additional PropertyEditors = registered through CustomEditorConfigurer, if that's what you meant! The = BeanWrapper doesn't know of anything like an ApplicationContext when just = instantiating it. I'm using the BeanWrapperImpl in some rare cases as well (same reason, = it's really convenient). I wouldn't know how to add additional custom editors to beanwrappers instantiated manually. The solution Guillaume is suggesting (with Sun's PropertyManager) will not work; since Spring doesn't use it (security restrictions might give problems there). Alef > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On = Behalf > Of Chris Winters > Sent: Friday, March 05, 2004 4:58 PM > To: spr...@li... > Subject: Re: [Springframework-developer] "permanantly" registering > property editor with BeanWrapper? >=20 > Alef Arendsen wrote: > > It's not possible to do this via a static on the BeanWrapper. It IS > possible > > however... > > > > J=FCrgen added a CustomEditorConfigurer that you can use to do this. = Just > add > > it to you app context and you're done. > > > > <!-- taken from JavaDOC --> > > <bean id=3D"customEditorConfigurer" > > ... >=20 > Excellent! That should work just fine. >=20 > > If you're programmatically using the BeanFactory, you can add > > propertyeditors using registerCustomEditor from the BeanFactory (or = use > a > > BeanFactoryPostProcessor). >=20 > This is what I started doing, but if I instantiate a > BeanWrapperImpl myself the editors aren't available. (I'm just > using the BeanWrapper as a shortcut to do some property mapping > because it's so darned convenient.) >=20 > Plus I'm not sure how to do this from an ApplicationContext vs. a > BeanFactory -- the registerCustomEditor() seems to be implemented > in AbstractBeanFactory which doesn't seem to be a parent of any > ApplicationContext class. (I'm a little hazy on the relationships > among the objects at this level tho.) >=20 > Thanks! >=20 > Chris >=20 > -- > Chris Winters (cwi...@op...) > Senior Software Architect >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |
|
From: Chris W. <cwi...@op...> - 2004-03-05 16:38:10
|
Alef Arendsen wrote: > Oops, I guess (no I don't guess, I know for sure ;-) manually instantiating > a BeanWrapperImpl won't give you the additional PropertyEditors registered > through CustomEditorConfigurer, if that's what you meant! The BeanWrapper > doesn't know of anything like an ApplicationContext when just instantiating > it. Yeah, that's what I meant. I guess the static method (adding the editor manually to the BeanWrapperImpl class) would be the way to go then since there aren't any dependencies on a AppContext/BeanFactory. Thanks, Chris -- Chris Winters (cwi...@op...) Senior Software Architect |
|
From: Eduardo I. I. <zi...@su...> - 2004-03-05 19:22:07
|
Chris Winters wrote:
> Plus I'm not sure how to do this from an ApplicationContext vs. a
> BeanFactory -- the registerCustomEditor() seems to be implemented in
> AbstractBeanFactory which doesn't seem to be a parent of any
> ApplicationContext class. (I'm a little hazy on the relationships among
> the objects at this level tho.)
As the CustomEditorConfigurer object implements BeanFactoryPostProcessor it will
be automatically called by the ApplicationContext and the custom editors will be
configured. So you can just declare the bean in the xml file and thats all.
If you are using just a BeanFactory it will no work and you will have to do
something like:
CustomEditorConfigurer c = new CustomEditorConfigurer();
c.setWhatever(..);
c.postProcessBeanFactory(beanFactory);
It raised me a question: what will happen if I do
CustomEditorConfigurer c = beanFactory.getBean("customEditorConfigurer");
c.postProcessBeanFactory(beanFactory);
Is it possible to register a post processor this way?
|