struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luis Arias" <l...@elysia.com>
Subject Localized default values in form beans...
Date Sun, 10 Sep 2000 08:25:58 GMT
Hello !

I am confronted with the following problem in using struts for which I have
identified a possible solution.  I would like the community's comments on
this and any suggestions on other alternatives.

The problem is that I would like to be able to show localized default values
for form properties the first time a user brings up a particular page.  I
would like to do this using a straightforward mechanism that integrates
appropiately into the framework.

The reason why it is difficult to do this now, is because there is currently
no relationship between an ActionForm and the user's session.  Furthermore,
the bean is instanciated automagically by the ActionServlet using a noarg
constructor when handling a form submission.  This makes it difficult to
have form property values that are localized since the form bean does not
have a handle on the user's locale.

One solution to this would be to decide that ActionForm's must be
instanciated using a constructor that accepts the user's locale as an
argument, and implement this behavior with the accessor methods in an
ActionFormBase abstract class.  The createFormInstance() method in
ActionMappingBase would have to be modified to call the appropiate
constructor using reflection instead of simply calling newInstance().  This
way, an ActionForm could count on having access to a "locale" instance
variable when retrieving localized content.

The reason for doing this in the constructor is in order not to interfere
with the
population of the form bean's properties, although this may not be an issue
since the locale instance variable would not be of type String.  An
alternative
would be to define a setLocale(Locale locale) method in the ActionForm
interface which would be implemented in the ActionFormBase class.

Both of these solutions raise compatibility issues with existing code...

It also comes across my mind that there might be a general need for
different parts of the framework to access others, so it might be worthwhile
to think about a StrutsContext convenience class (kind of like a PageContext
for jsp's) which could be used to pass this sort of stuff around (locale,
session, request, etc...) in a simple uniform manner.

I'm ready to implement the "locale" solution, but will need some help in
designing a StrutsContext if that is what needs to be done.  What should we
do here ?  Are there any other alternatives which I haven't seen ?

Thanks,

--
Luis Arias
Elysia - http://www.elysia.com
1, rue de Stockholm
75008 PARIS
FRANCE
+33 1 44 70 70 90
+33 1 44 70 72 09 fax
+33 6 14 20 87 93 mobile




Mime
View raw message