Re: MessagesResources - some thoughts

2001-02-16 Thread Craig Tataryn

But technically couldn't the application developer do this already?  They
could just add another init-param to the Servlet which specified a
Resources class other than the default.  The servlet writter would simply
use this resource bundle instead, getting it's messages from there.

You could have something like UIResource and ServletResource classes.  The
UIResource class would be the one you set in the ActionServlet's
application init-param, and the ServletResource class can be loaded
programatically by the servlet writter based on some custom init-param
which specified the class name.

Craig T.

Rob Leland wrote:

 Roland Huss wrote:
 
  Hi,
 
  for some reasons I would like to separate messages put into JSP-pages
  with bean:message from messages generated within java
  code.
 +1
 This sounds like a good Idea. I would vote for this change.
 Maybe you could post it to the bug/feature request so it
 ends up one the list for version 1.1.

 -Rob

--
I've been trying to change the world for years, but they just won't give me
the source code



begin:vcard 
n:Tataryn;Craig
tel;home:952-884-6752
tel;work:952-842-5576
x-mozilla-html:TRUE
url:http://www.computer-programmer.org
org:Compuware;Professional Division
adr:;;3600 West 80th St. Suite 400;Bloomington;MN;55431;United States of America
version:2.1
email;internet:[EMAIL PROTECTED]
title:Senior Staff Analyst
fn:Craig Tataryn
end:vcard



MessagesResources - some thoughts

2001-02-14 Thread Roland Huss

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