Hi Niall,

Thanks again for your help - your suggestion worked.

Sean 

-----Original Message-----
From: Niall Pemberton [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 23, 2006 11:03 AM
To: Struts Users Mailing List
Subject: Re: Resource bundles and Struts taglibs

On 8/23/06, O'Shea, Sean <Sean.O'[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm using struts 1.2.9 and I'm having some trouble with resource
> bundles. My JSP looks like this:
>
> <%@ include file="../taglibs.jsp" %>
> <logic:messagesPresent>
>         <h3 class="red"><bean:message key="errors.header"
> bundle="otherBundle"/></h3>
>         <bean:message key="errors.subheader" bundle="otherBundle" />
>         <ul>
>                 <html:messages id="error">
>                         <li><bean:write name="error"
> bundle="otherBundle" /></li>
>                 </html:messages>
>         </ul>
>         <hr>
> </logic:messagesPresent>
>
> I'm plugging my resources into my struts-config.xml like this:
>
> <message-resources parameter="resources.ApplicationResources"
> null="false"/>
> <message-resources key="otherBundle" parameter="resources.OtherBundle"
> null="false"/>
>
> Both the bean:message messages get outputted as expected. This means
> that the otherBundle resources are definitely registered with the
> application.
>
> However, the bean:write message does not get outputted as expected - I
> get a ??? errors.foo.bar ??? message on the JSP

Its the <html:messages> tag that is converting the keys in your error
messages into the text - <bean:write> is just accessing the page scope
variable that the text has been stored under and writing it out. The
bundle attribute for <bean:write> is for use with the "formatKey"
attribute.

You need to specify the bundle on the <html:messages> tag:

  <html:messages id="error" bundle="otherBundle">
        <li><bean:write name="error" /></li>
   </html:messages>

Niall

> I've debugged the tag libraries and I think both bean:message and
> bean:write call the org.apache.struts.taglib.TagUtils.message method
> detailed below:
>
>     public String message(
>             PageContext pageContext,
>             String bundle,
>             String locale,
>             String key,
>             Object args[])
>             throws JspException {
>
>         MessageResources resources =
>                 retrieveMessageResources(pageContext, bundle, false);
>
>         Locale userLocale = getUserLocale(pageContext, locale);
>         String message = null;
>         if (args == null) {
>             message = resources.getMessage(userLocale, key);
>         } else {
>             message = resources.getMessage(userLocale, key, args);
>         }
>         if ((message == null) && log.isDebugEnabled()) {
>             // log missing key to ease debugging
>             log.debug(resources.getMessage("message.resources", key,
> bundle, locale));
>         }
>         return message;
>     }
>
> When the bean:message tag is calling this method, the bundle parameter
> has a value of 'otherBundle'.
>
> However, when the bean:write tag calls this method the bundle
parameter
> is null - hence the ??? errors.foo.bar ??? message in my JSP.
>
> Can someone offer advice on this issue? Do I have my JSP and
> struts-config.xml configured correctly?
>
> Any help would be greatly appreciated
>
> Thanks
>
> Sean
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

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



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

Reply via email to