You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Frank Nguyen <fr...@cp.net> on 2000/08/08 20:23:01 UTC

struts:message tag does not recognize bundle or locale attribute

I am using tomcat standalone server (v3.1) on NT4.0 Server/JDK1.2.

I can't seem to make the <struts:message> tag to recognize the bundle or
locale attribute?
Here is my code snippet:
    <%
    String bundleName = "MyApp";
    String acceptLanguage = request.getHeader("Accept-Language");
    String acceptCharset  = request.getHeader("Accept-Charset");

    LocaleNegotiator negotiator =
        new LocaleNegotiator( bundleName, acceptLanguage, acceptCharset );

    Locale lastLocale = negotiator.getLocale();
    String charset = negotiator.getCharset();
    ResourceBundle bundle = negotiator.getBundle();
    %>

    <html>
    <head>
    <title>
    <struts:message bundle="<%=bundle%>" locale="<%=lastLocale%>"
key="logon.title"/>
    </title>
    </head>

Whenever I specify these two attributes, I would get the following error:
    javax.servlet.ServletException: Missing resources attribute

Thanks for your help.


Re: struts:message tag does not recognize bundle or locale attribute

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
(Sorry for the late response).

Frank Nguyen wrote:

> I am using tomcat standalone server (v3.1) on NT4.0 Server/JDK1.2.
>
> I can't seem to make the <struts:message> tag to recognize the bundle or
> locale attribute?
> Here is my code snippet:
>     <%
>     String bundleName = "MyApp";
>     String acceptLanguage = request.getHeader("Accept-Language");
>     String acceptCharset  = request.getHeader("Accept-Charset");
>
>     LocaleNegotiator negotiator =
>         new LocaleNegotiator( bundleName, acceptLanguage, acceptCharset );
>
>     Locale lastLocale = negotiator.getLocale();
>     String charset = negotiator.getCharset();
>     ResourceBundle bundle = negotiator.getBundle();
>     %>
>
>     <html>
>     <head>
>     <title>
>     <struts:message bundle="<%=bundle%>" locale="<%=lastLocale%>"
> key="logon.title"/>
>     </title>
>     </head>
>
> Whenever I specify these two attributes, I would get the following error:
>     javax.servlet.ServletException: Missing resources attribute
>

The <struts:message> tag is actually expecting the name of a session scope
attribute under which the user's desired Locale has been stored.  It defaults
to the value of the String constant Action.LOCALE_KEY.

To modify this example so that it works,you would need to add the followling
line after the "Locale lastLocale = ...":

    pageContext.setAttribute("lastLocale", lastLocale,
PageContext.SESSION_SCOPE);

and change the <struts:message> tag like this:

    <struts:message ... locale="lastLocale"/>

However, in the same way, it is expecting the bundle attribute to be the name
of an application scope object of type org.apache.struts.util.MessageResources
-- not ResourceBundle.  So, you would need to construct and store a
MessageResources object, rather than a ResourceBundle, for this to work.

>
> Thanks for your help.

By the way, is your LocaleNegotiator class available anywhere?  Something like
that would be very interesting to have -- among other things, Tomcat needs
something like it to figure out what value(s) to return for the
ServletRequest.getLocale() and getLocales() methods.

Craig