Hi,

for some reasons I would like to separate messages put into JSP-pages
with <bean:message> from messages generated within java
code. I.e. packaging your application as jar file and still give
designers a change to customize messages (without touching the jars)
seems to be a good  idea (at least for me ;-)

Hence I'v written a MessageResources subclass, which fetches the
properties from a file somewhere below the serlvet context. However,
there are some problems with the current design of the MessageResource
handling of struts:

  * Theres no easy way to pass extra parameters to the
    MessageResourcesFactory when creating the application resources. 

  * PropertyMessageResources is hard to subclass

==================================================

My solution for now  is to subclass
PropertyMessageResources and to duplicate the loadLocale() method
nearly completely except for obtaining the properties' InputStream:


  URL resource = servletCtx.getResource(name);
  is = resource.openConnection().getInputStream();

instead of  
 
  is = this.getClass().getClassLoader().getResourceAsStream(name);

(serlvetCtx is the ServletContext obtained from my own
MessageResourcesFactory)

Furthermore I have to use a subclassed ActionServlet
which duplicates nearly everything from 'initApplication()' except
for: 

  .......
  MessageResourcesFactory factoryObject =
                MessageResourcesFactory.createFactory();

  // Set servlet context to our factory (nasty...)
  if (factoryObject instanceof CtxMessageResourcesFactory)
  {
     ( (CtxMessageResourcesFactory) factoryObject).setServletCtx(
           getServletConfig().getServletContext());
  }
  .......
===================================================

My suggestion is to extract the creation of the  InputStream in
PropertyMessageResources into an extra method like

 protected InputStream getInputStream(String name)
 {
    return this.getClass().getClassLoader().getResourceAsStream(name);
 }

so that it can be subclassed without duplicating the caching stuff.

For the problem with passing extra parameters to a
MessageResourcesFactory I don't see any solution. Except maybe (at
least for my case) to include a ServletContext attribute directly into
the base MessageResources class, which is maybe not so a bad idea in
general.  Or even a protected initMessageResourcesFactory() (which
does nothing in the default case) in ActionServlet would be of much
help.

Are there any chance for getting this or something similar into the
mainstream struts cvs tree ?

cu...
-- 
                                                        ...roland huss
                                                             consol.de

Reply via email to