MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Determine 'Locale' | << | >> |
This section explains
how to customize determining Locale
with PageServlet
.
You can skip this section if you have no interest in locale sensitive response renderring.
Class diagram in this section is shown below:
Classes which you must define are colored, and other are already defined.
In this tutorial, abbreviated class names are used. Complete names are shown below.
Notation | Full name |
---|---|
ConsumerContext | jp.ne.dti.lares.foozy.pagemixer.mixer.ConsumerContext |
LocaleFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.LocaleFactory |
PageServlet | jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet |
ParameterKey | jp.ne.dti.lares.foozy.pagemixer.servlet.ParameterKey |
SessionKey | jp.ne.dti.lares.foozy.pagemixer.servlet.SessionKey |
Notation | Full name |
---|---|
CustomLocaleFactory | pagemixer.servlet.CustomLocaleFactory |
Servlet API provides
HttpServletRequest#getLocale()
to get Locale
of current request.
In addition to it,
by customization of determining Locale
,
PageMixer allows you to determine Locale
per request
in the other ways. For example:
Locale
of runtime environmemt
Locale
value
Locale
name from request parameter
Locale
in session
LocaleFactory
PageMixer provides
"LocaleFactory
" for
customization of determining Locale
.
In almost all cases,
you can satisfy your needs
by overriding create
method of it,
event though it has more overridable methods for complex purpose.
Please see API document for detail about them.
public Locale create(ConsumerContext context)
Sample overriding is shown below.
String value = (String)(context.getValue(KEY_PARAM_LOCALE)); Locale locale = (Locale)(context.getValue(KEY_SESSION_LOCALE)); if(null != value){ locale = new Locale(value, "", ""); context.setValue(KEY_SESSION_LOCALE, locale); } else if(null == locale){ locale = Locale.getDefault(); } return locale;
In this example,
KEY_PARAM_LOCALE
and
KEY_SESSION_LOCALE
are
instances of ParameterKey
and
SessionKey
.
So, above sample determines Locale
in steps shown below.
Locale
if request parameter is specified,
Locale
in session if it is already stored in, or
Locale
of runtime environment otherwise
LocaleFactory
does not requires any
initialization parameters.
To use your custom LocaleFactory
,
you should specify "servlet.localeFactory
"
Servlet init-param in deployment descriptor
as shown below.
<init-param> <param-name> servlet.localeFactory </param-name> <param-value> pagemixer.servlet.CustomLocaleFactory </param-value> </init-param>
MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Determine 'Locale' | << | >> |