Quoting Andreas Schildbach <[EMAIL PROTECTED]>:

> Kris Schneider wrote:
> 
> > You may also need to override HttpServletRequestWrapper.getHeaders so that
> it
> > returns a non-empty Enumeration for the Accept-Language header. In other
> words,
> > always make JSTL think that the client has supplied the header. JSTL
> should
> > then use ServletRequest.getLocales for the list of preferred locales.
> 
> This works, thanks!
> 
> I guess the Jakarta implementation is violating the JSTL spec 1.1 then, 
> which states at several places that ServletRequest.getLocales() is used 
> for determining the browser-based locale setting (e.g. 8.2.1, 8.3.2, 9.3.3).
> 
> Also, my feeling is that it is bad to fake request headers.

Ignoring JSTL for a moment, think about the specification requirements for the
relationship between the getLocale/getLocales methods and the Accept-Language
header. If the Accept-Language header is present, getLocale/getLocales must
honor its value. If it's not present, getLocale/getLocales must return the
default locale for the server - Locale.getDefault(). So, if you're working
backwards by making getLocale/getLocales return values that may not have
anything to do with the Accept-Language header, then you also need to make sure
that the various header-related methods reflect those values in the
Accept-Language header. Which means overriding HttpServletRequest's
getHeaderNames, getHeaders, and getHeader methods. Otherwise, your wrapper
really isn't compliant with the spec.

Having said all that, if this is just aimed at configuring JSTL then you may
want to ditch the wrapper and use javax.servlet.jsp.jstl.core.Config in your
filter. For example:

Locale locale = getUserLocale(); // implements your locale selection process
Config.set(request, Config.FMT_LOCALE, locale);
chain.doFilter(request, response);

> I just had a look at the Jakarta source, and it makes clear why it is 
> peeking directly at the request headers. This is because the authors 
> want to work around the default locale mechanism that is included in 
> ServletRequest.getLocales().
> 
> Maybe we should try to convince the community to make that default 
> mechanism optional for the next Servlet spec revision, for example by 
> having to declare the default in the web.xml if it is desired.
> 
> Regards,
> 
> Andreas

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to