You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bart Busschots <ba...@cs.nuim.ie> on 2006/03/22 01:30:34 UTC
Is there a 'right' way to get a resource bundel given a JSP Page
Context?
The Struts app I'm developing uses a number of customs JSP tags that we
have written oursevelves in an attempt to speed up repetative tasks and
to compltely remove the need for us to use Scriptlets which not nice to
have floating round your code. I developed a static helper function that
is used within our custom tags to get a MessageResources object given a
JspContext object and it worked perfectly while we only had one locale.
Today I got a translation of our resources.properties file in Irish for
the entire app and was horrified to see that when I added a
respources_ga.properties it was picked up perfectly by the standard JSP
tags but not by any of our custom tags. Below is the code for my
function, can anyone see where I am going wrong. Thanks a million,
Bart Busschots,
NUI Maynooth.
public static MessageResources getMessageResources(JspContext theJSPPage){
MessageResources resources = null;
String bundle = Globals.MESSAGES_KEY;
PageContext pageContext = (PageContext)theJSPPage;
if(resources == null) {
resources = (MessageResources)pageContext.getAttribute(bundle,
PageContext.REQUEST_SCOPE);
}
if(resources == null) {
ModuleConfig moduleConfig = getModuleConfig(pageContext);
resources = (MessageResources)pageContext.getAttribute(bundle +
moduleConfig.getPrefix(), PageContext.APPLICATION_SCOPE);
}
if(resources == null) {
resources = (MessageResources)pageContext.getAttribute(bundle,
PageContext.APPLICATION_SCOPE);
}
if(resources == null) {
throw new VTException("Failed to get Mesage Resources.");
}
return resources;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org