struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@blueyonder.co.uk>
Subject Re: help message resources
Date Fri, 18 Jun 2004 22:45:10 GMT
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: <sale1975@inwind.it>
To: "struts-user" <struts-user@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


Mime
View raw message