You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "sale1975@inwind.it" <sa...@inwind.it> on 2004/06/18 11:03:54 UTC

help message resources

Hi,
i 'm tring to change the message visualization (i don't want to show the user a
message like '???foo???') when the key of the message is not present in my
ApplicationResources files. how can i do ? 
The only solution i found is to modify the method message(pageContext, bundle,
locale, key, args[]) of the RequestUtils class adding at the end the following
lines:

if(result.startWith("???") && result.endWith("???")){
  result= (resources.getMessage(userLocale,"keynotFound.message");
}

Is there cleaner way to do this???
Thanks.
Ale



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: help message resources

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Rather than modifying RequestUtils why not configure Struts to use your own
MessageResources implementation:

http://jakarta.apache.org/struts/userGuide/configuration.html

1) Extend PropertyMessageResources setting the returnNull property to 'true'
in the constructor and overriding the getMessage() method

public class MyMessageResources extends PropertyMessageResources {

    // N.B. calls parent class constructor with returnNull = true
    public MyPropertyMessageResources(MessageResourcesFactory factory,
String config) {
        super(factory, config, true);
    }

     public String getMessage(Locale locale, String key) {
        String msg = super.getMessage(locale, key);
        return msg == null ? "keynotFound.message" : msg;
     }

}


2) Create a Factory for your MessageResources implementation

public class MyMessageResourcesFactory extends MessageResourcesFactory {

   public MessageResources createResources(String config) {
        return new MyMessageResources(this, config);
    }
}


3) Configure Struts to use your MessageResources class. In the
struts-config.xml

   <message-resources parameter="...."
factory="mypackage.MyMessageResourcesFactory "/>


Niall

----- Original Message ----- 
From: <sa...@inwind.it>
To: "struts-user" <st...@jakarta.apache.org>
Sent: Friday, June 18, 2004 10:03 AM
Subject: help message resources


Hi,
i 'm tring to change the message visualization (i don't want to show the
user a
message like '???foo???') when the key of the message is not present in my
ApplicationResources files. how can i do ?
The only solution i found is to modify the method message(pageContext,
bundle,
locale, key, args[]) of the RequestUtils class adding at the end the
following
lines:

if(result.startWith("???") && result.endWith("???")){
  result= (resources.getMessage(userLocale,"keynotFound.message");
}

Is there cleaner way to do this???
Thanks.
Ale



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: help message resources

Posted by Nick Heudecker <ni...@systemmobile.com>.
 From a document I wrote some time ago:

"Setting the null attribute to 'false' will display missing resource 
values as ???key??? instead of displaying null. This string is easily 
found during automated testing of your JSPs, making in-container unit 
testing more complete."

Here's what you set to false in the struts-config.xml:
<message-resources 
parameter="com.systemmobile.example.ApplicationResources" null="false"/>

You can find the complete document here:
http://www.systemmobile.com/articles/strutsMessageResources.html

sale1975@inwind.it wrote:

> Hi,
> i 'm tring to change the message visualization (i don't want to show the user a
> message like '???foo???') when the key of the message is not present in my
> ApplicationResources files. how can i do ? 
> The only solution i found is to modify the method message(pageContext, bundle,
> locale, key, args[]) of the RequestUtils class adding at the end the following
> lines:
> 
> if(result.startWith("???") && result.endWith("???")){
>   result= (resources.getMessage(userLocale,"keynotFound.message");
> }
> 
> Is there cleaner way to do this???
> Thanks.
> Ale
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


-- 
Nick Heudecker
System Mobile, Inc.
Email: nick@systemmobile.com
Web: http://www.systemmobile.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org