Thanks Niall. If I were to use <set-property> elements, do you have any idea how I would retrieve those properties within the factory?
Thanks, David "Niall Pemberton" <[EMAIL PROTECTED]> wrote on 06/16/2005 04:03:36 PM: > You need to configure your message resources through the struts-config.xml - > init parameters in the web.xml don't work in Struts 1.2 > > http://struts.apache.org/userGuide/configuration.html#resources_config > > So in your case you need something like the following in your > struts-config.xml.... > > <message-resources parameter="..." > factory="org.example.MyMessageResourceFactory " /> > > You can use the "parameter" element for any configuration value you want - > thats the argument passed to the factory's createResources() method. I > believe you can also use <set-property> elements for other config values - > although I've never actually tried it out. > > Niall > > ----- Original Message ----- > From: <[EMAIL PROTECTED]> > Sent: Thursday, June 16, 2005 8:03 PM > > > > I have a project where I want to use the Struts Validator. By default the > > error messages are read from a properties file. However I'm required to > > read the error messages from a database. The question is how do I do this? > > I found this article > > http://www.informit.com/articles/article.asp?p=101174&rl=1, from the > > "Struts Kick Start" book, which shows how to do this but it doesn't seem > > to work. > > > > Here is what I did. First I created a MessageResourcesFactory that creates > > my version of MessageResources: > > > > import org.apache.struts.util.MessageResources; > > import org.apache.struts.util.MessageResourcesFactory; > > > > public class MyMessageResourceFactory extends MessageResourcesFactory { > > > > public MessageResources createResources(String arg0) { > > return new DbMessageResources(this, arg0); > > } > > } > > > > Next I created my version of MessageResources: > > > > import java.util.Locale; > > import org.apache.struts.util.MessageResources; > > import org.apache.struts.util.MessageResourcesFactory; > > > > public class DbMessageResources extends MessageResources implements > > java.io.Serializable > > { > > > > public MessageResource(MessageResourcesFactory arg0, String arg1) > > { > > super(arg0, arg1); > > } > > > > public String getMessage(Locale arg0, String key) { > > // based on locale and key, retrieve message from database > > // for this example just return the key > > return key; > > } > > > > } > > > > Lastly, the article says to add these parameters ("application" and > > "factory") to the ActionServlet config in web.xml file to tell Struts to > > use my implementation. > > > > <servlet> > > <servlet-name>action</servlet-name> > > <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> > > <init-param> > > <param-name>config</param-name> > > <param-value>/WEB-INF/struts-config.xml</param-value> > > </init-param> > > <param-name>application</param-name> > > <param-value>org.example.DbMessageResources</param-value> > > </init-param> > > <init-param> > > <param-name>factory</param-name> > > <param-value>org.example.MyMessageResourceFactory </param-value> > > </init-param> > > <load-on-startup>2</load-on-startup> > > </servlet> > > > > Trouble is this code never gets called. I'm on Struts 1.2.7. Is this the > > right way to get Struts to use my version of MessageResources, or is there > > a different way to do this now? I've searched for more documentation > > regarding reading resources from the database, but haven't found much. Any > > hints, tips, or references would be greatly appreciated. > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

