jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fred <frederi...@in-fusio.com>
Subject Fwd: i18n LocaleTag & FormatDateTimeTag: problem getting the right locale.
Date Wed, 22 Aug 2001 08:29:38 GMT

Cross-posted on the User mailing list.

-------------------------------------------------------


Hi,

	I'm currently changing my date tag to use the i18n ones but there seem to be
a problem in the LocaleTag class. If the locale is not given has a parameter
the LocaleTag & FormatDateTimeTag use the LocaleTag.getLocale( pageContext )
method to retreive the correct locale. The problem is that this method check
first the response locale. It's a good idea if we want to reply in another
language but in the servlet API from Sun we can found that the
response.getLocale() return the server locale by default. ("By default, the
response locale is the default locale for the server." in setLocale()
description at http://java.sun.com/products/servlet/2.2/javadoc/index.html )
So this method ALWAYS return something not null ! I have the latest release
(today 21/08/2001). Is this a misunderstand of the usage of the tag libray
from myself, or a problem from my web server (Tomcat 3.2.3) or is this a
mistake in the i18n tag library ?

Thanks in advance.
Fred.

Copy of the getLocale() Method from LocaleTag :

    /** Extracts the {@link Locale} from the given {@link ServletRequest}
      * or returns the default JVM's {@link Locale} if it could not be found
      */
    protected static Locale getLocale( PageContext pageContext ) {
        Locale answer = pageContext.getResponse().getLocale();
        if ( answer == null ) {
            ServletRequest request = pageContext.getRequest();
            answer = request.getLocale();
            if ( answer == null ) {
                for ( Enumeration enum = request.getLocales();
enum.hasMoreElements(); ) {
                    answer = (Locale) enum.nextElement();
                    if ( answer != null ) {
                        break;
                    }
                }
                if ( answer == null ) {
                    // XXXX: may wish to log warning?
                    answer = Locale.getDefault();
                }
            }
        }
        return answer;
    }

-------------------------------------------------------

Mime
View raw message