|
From: JP P. <jp....@ti...> - 2003-07-20 11:23:08
|
Thanks, Juergen. This is very powerful, also for custom PropertyEditors!
I don't know about current status, but a half year ago, this was not
possible in the Struts-Validator.
I didn't realize that the InitBinder is called on each request.
Regards,
Jean-Pierre
-----Message d'origine-----
De=A0: j=FCrgen h=F6ller [werk3AT] [mailto:jue...@we...]=20
Envoy=E9=A0: dimanche 20 juillet 2003 12:46
=C0=A0: JP Pawlak; spr...@li...
Objet=A0: Re: [Springframework-developer] Locale aware binding
Hi Jean-Pierre,
=20
CustomDateEditor and CustomNumberEditor and meant to be registered
explicitly, as they depend on specific parameters like the current
locale. They can be configured to use any DateFormat resp. NumberFormat
for parsing, and to either set empty values to null or throw an
exception. They will also get applied for rendering on
Errors.getFieldValue and thus BindStatus evaluation within a bind tag.
=20
In a BaseCommandController subclass like one of the form controller
classes, you can override initBinder to call registerCustomEditor on the
ServletRequestDataBinder instance used. A custom editor can be
registered for either all fields of the given type or just a specific
field. RequestContextUtils.getLocale will return the current locale as
determined by the LocaleResolver, to retrieve a specific NumberFormat or
DateFormat instance. E.g.:
=20
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws ServletException {
Locale locale =3D RequestContextUtils.getLocale(request);
DateFormat dateFormat =3D DateFormat.getDateInstance(DateFormat.SHORT,
locale);
binder.registerCustomEditor(Date.class, new
CustomDateEditor(dateFormat, false));
}
=20
Regards,
Juergen
=20
=20
-----Urspr=FCngliche Nachricht-----=20
Von: JP Pawlak [mailto:jp....@ti...]=20
Gesendet: So 20.07.2003 10:39=20
An: spr...@li...=20
Cc:=20
Betreff: [Springframework-developer] Locale aware binding
=09
=09
Hi everyone,
=20
Knows anyone how to make locale specific databindings?
I have seen date and number propertiesEditors using apparently
localized binding. But how the binder knows which Locale to use? As =
it=92s
not the system Locale which is to be used, but the user=92s one.
=20
Regards,
Jean-Pierre
=20
|