You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Timo Tjäder <tj...@mikropc.net> on 2004/03/18 20:50:07 UTC

How to use MessageResources effectively?

Hello,

I have a Bean that my form uses directly to display a 
HTML control <html:select>. This requires localizied
access to the message bundle. Currenty I do not have
user session available in this Bean and i get the
handle to the message resources as follows.

this.resources =    MessageResources.getMessageResources("ApplicationMessageResources");

Everything works just fine, but what makes me worry is that
the debug log seems to download the whole bundle. Is there a more 
clever  way to solve this problem (just switch to another
language bundle), without reading the MessageResource again.

Any good ideas or solutions are wery welcome. However, it seems
that only this way the user language was really changed.

Thanks,

Timo

<short pseudo code of the bean>
public Collection getBeanDiscTypeCollection() {
	String myL = getMyLocale().getLanguage();
	String myC = getMyLocale().getCountry();
	Locale l = new Locale(myL,myC);
	if (beanDiscTypeCollection == null) {
	   if (this.resources == null) {
	      this.resources =
	      MessageResources.getMessageResources("ApplicationMessageResources");
	    }
...
	    Vector entries = new Vector(maxDiscTypes + 1);
	    for (int i = 0; i <= maxDiscTypes; i++) {
...	
         	codeLabel =
			resources.getMessage(l,"option.media.disctype." + i);
			entries.add(new LabelValueBean(codeLabel, "" + i));
            }
		beanDiscTypeCollection = entries;
	}
         return (beanDiscTypeCollection);
}


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