You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Fred <fr...@in-fusio.com> on 2001/08/22 10:29:38 UTC

Fwd: i18n LocaleTag & FormatDateTimeTag: problem getting the right locale.

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;
    }

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