The code we are using to locate the properties files associated with the "ui" key is subclassed from org.apache.struts.util.PropertyMessageResources. We have modified the loadLocale method to be able to find the message resource in a directory other than one in the class path. As I stated before, this approach is working in our application - our entire user interface is translated using text from our resource files. Only once I try to subclass a <form-bean> element do I get this problem. I am able to subclass a <form-property> element successfully. The struts_config_1_1.dtd indicates that it is valid to use "className" on a <form-bean> element, so I am not breaking the definition of struts-config.xml
Can someone try what I am trying on their working Struts application to see if this works for them? I still don't think the error message I am getting is truly indicative of the real problem. Here is our loadLocale method ----------------------------- protected void loadLocale(String localeKey) { if (log.isTraceEnabled()) { log.trace("loadLocale(" + localeKey + ")"); } // Have we already attempted to load messages for this locale? synchronized (locales) { if (locales.get(localeKey) != null) return; locales.put(localeKey, localeKey); } // Set up to load the property resource for this locale key, if we can String name = config.replace('.', '/'); if (localeKey.length() > 0) name += "_" + localeKey; name += ".properties"; InputStream is = null; Properties props = new Properties(); // Load the specified property resource try { if (log.isTraceEnabled()) { log.trace(" Loading resource '" + name + "'"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } // BEGIN CUSTOM MODIFICATION // Attempt to locate the context root. This is complicated // by the fact that we do not have access to any of the // Servlet context objects. So we will instead try to get // the URL of a well known resources, and extrapolate from it // the location of the context root. We are loading a resource // from a jar file we KNOW must exist in WEB-INF/lib, so we can // do a little string parsing on it to find the parent of // WEB-INF which will then be the web app context root. viola. // boolean isRelative = name.startsWith("/"); if (isRelative) { URL dtd = classLoader.getResource("org/apache/struts/resources/struts-config_1_0.dtd") ; // // getResource() returns: // jar:<path to jar>!/org/apache/struts/resources/struts-config_1_0.dtd // example // jar:file:/C:/eSales/apps/FSP/webapps/fsp/WEB-INF/lib/struts.jar!/org/apache/ struts/resources/struts-config_1_0.dtd // if (null != dtd) { String contextRoot = dtd.toString(); int webinfLocation = contextRoot.indexOf("/WEB-INF"); if (contextRoot.startsWith("jar:file:") && webinfLocation > -1) { name= contextRoot.substring(9, webinfLocation) + name; try { is = new FileInputStream(name); } catch (FileNotFoundException e) { // probably not a big deal, by design many // files will not be found (ex: file_en_US.properties) } } } } else { // default behavior is = classLoader.getResourceAsStream(name); } // END CUSTOM MODIFICATION if (is != null) { props.load(is); is.close(); } if (log.isTraceEnabled()) { log.trace(" Loading resource completed"); } } catch (Throwable t) { log.error("loadLocale()", t); if (is != null) { try { is.close(); } catch (Throwable u) { ; } } } // Copy the corresponding values into our cache if (props.size() < 1) return; synchronized (messages) { Enumeration names = props.keys(); while (names.hasMoreElements()) { String key = (String) names.nextElement(); if (log.isTraceEnabled()) { log.trace(" Saving message key '" + messageKey(localeKey, key)); } messages.put(messageKey(localeKey, key), props.getProperty(key)); } } } -----Original Message----- From: James Mitchell [mailto:[EMAIL PROTECTED]] Sent: Thursday, November 21, 2002 12:54 PM To: Struts Users Mailing List Subject: RE: Error "Cannot find message resources under key ui" when attempting to subclass FormBeanConfig in struts-config.xml I think you might be misunderstanding what the error means by key (unless I'm off base here) Can you post the code that you are using to find the key 'ui' You might also try this. Add this to your default resource file: ui=test See if that clears up your error. -- James Mitchell Software Engineer/Struts Evangelist http://www.open-tools.org "If you were plowing a field, which would you rather use? Two strong oxen or 1024 chickens?" - Seymour Cray (1925-1996), father of supercomputing > -----Original Message----- > From: Ahearn, Denis [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 21, 2002 1:49 PM > To: 'Struts Users Mailing List' > Subject: RE: Error "Cannot find message resources under key ui" when > attempting to subclass FormBeanConfig in struts-config.xml > > > Yes, my struts-config.xml has the following definition in it: > > <message-resources key="ui" > null="false" > parameter="/WEB-INF/conf/UserInterfaceResources" > > factory="com.mycompany.util.SpecifiedPropMsgResourcesFactory"/> > > The application where I am trying to subclass the FormBeanConfig is a > robust working Struts app, which has many <bean:message> tags that > successfully draw resources from the "ui" message resources. As soon > as I trying subclassing the FormBeanConfig of any <form-bean> element, > the exception starts happening. > > Here is my code for the MyFormBeanConfig class: > > ---------------------------------- > > package mypackage; > > import org.apache.struts.config.FormBeanConfig; > > public class MyFormBeanConfig extends FormBeanConfig > { > protected String callbackClassName; > > public MyFormBeanConfig() > { > super(); > callbackClassName = null; > } > > public String getCallbackClassName() > { > return this.callbackClassName; > } > > public void setCallbackClassName(String callbackClassName) > { > this.callbackClassName = callbackClassName; > } > } > > I am wondering if the "Cannot find message resources under key ui" > error message I am getting is not indicative of the true problem. I > really don't think anything is wrong with how I have set up my message > resources, but I could be wrong. > > Thanks again, > Denis > > > -----Original Message----- > From: James Mitchell [mailto:[EMAIL PROTECTED]] > Sent: Thursday, November 21, 2002 12:41 PM > To: Struts Users Mailing List > Subject: RE: Error "Cannot find message resources under key ui" when > attempting to subclass FormBeanConfig in struts-config.xml > > > Apparently, you are trying to use a 'message resources under key ui' > and it is not found :/ > > Have you validated that it is there? > > Can you post your Dyna extension? > > > > -- > James Mitchell > Software Engineer/Struts Evangelist > http://www.open-tools.org > > "If you were plowing a field, which would you rather use? Two strong > oxen or 1024 chickens?" > - Seymour Cray (1925-1996), father of supercomputing > > > > -----Original Message----- > > From: Ahearn, Denis [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, November 21, 2002 12:51 PM > > To: '[EMAIL PROTECTED]' > > Subject: Error "Cannot find message resources under key ui" when > > attempting to subclass FormBeanConfig in struts-config.xml > > > > > > Has anyone successfully subclassed the FormBeanConfig associated > > with a <form-bean> element? > > > > For example: > > <form-bean name="myForm" > > type="org.apache.struts.action.DynaActionForm" > > className="mypackage.MyFormBeanConfig"> > > . > > . > > . > > </form-bean> > > > > When I try this, I get the following exception: > > > > javax.servlet.ServletException: Cannot find message resources under > > key ui > > at > > org.apache.jasper.runtime.PageContextImpl.handlePageException(PageCo > > nt > > extImp > > l.java:494) > > at org.apache.jsp.logon_jsp._jspService(logon_jsp.java:280) > > at > > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136) > > at > > javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > > at > > > org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper. > java:2 > > 04) > > at > > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289) > > at > > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240) > > at > > javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > > at > > > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli > cation > > FilterChain.java:247) > > at > > > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi > lterCh > > ain.java:193) > > at > > > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa > lve.ja > > va:260) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:643) > > at > > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java > :480) > > at > > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > > at > > > org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa > lve.ja > > va:191) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:643) > > at > > > org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticat > orBase > > .java:471) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:641) > > at > > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java > :480) > > at > > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > > at > > org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396) > > at > > > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja > va:180 > > ) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:643) > > at > > > org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcher > Valve. > > java:170) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:641) > > at > > > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja > va:172 > > ) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:641) > > at > > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java > :480) > > at > > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > > at > > > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv > e.java > > :174) > > at > > > org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext > .invok > > eNext(StandardPipeline.java:643) > > at > > > org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java > :480) > > at > > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) > > at > > org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) > > at > > org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405) > > at > > > org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proces > sConne > > ction(Http11Protocol.java:380) > > at > > org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508) > > at > > > org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPo > ol.jav > > a:533) > > at java.lang.Thread.run(Thread.java:479) > > > > I am using the Struts 1.1-b2, and Tomcat 4.1. If I remove the > > className="mypackage.MyFormBeanConfig" from my <form-bean> element, > > then my application works fine. > > > > Does anyone have any hints on what is causing this exception? > > > > Thanks, > > Denis > > > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>