You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mi...@ubsw.com on 2003/05/27 09:27:56 UTC

Clever way to externalize the values for the getKeyMethodMap() in the LookupDispatchAction?

I am trying to find a clever way to externalize the values for the getKeyMethodMap()?
I do not want to hard-code map.put( "form.button.add", "add" );
If there is anyone who has come up with a better way and would be willing to share, I would be very appreciative.

-------------------------
Thank You 
Mick Knutson 
Sr. Designer - Project Trust 
aUBS AG, Financial - Zürich 
Office: +41 (0)1/234.42.75 
Internal: 48194 
Mobile: 079.726.14.26 
-------------------------



Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Clever way to externalize the values for the getKeyMethodMap() in the LookupDispatchAction?

Posted by Kris Schneider <kr...@dotech.com>.
I'm not sure how clever it is, but that smells like a job for a properties file.
I'm not a big fan of doing things like I/O in constructors, so it might make
more sense to create the map in a plug-in and store it in application scope.
Normally, I'd say use a ServletContextListener if you've got a Servlet 2.3
container, but this is really to support Struts-specific functionality so I'd go
for the plug-in instead.

That being said, since the map values are method names that you have to
hard-code in your class anyway, the only real flexibility this seems to provide
is in the resource key. As an aside, I probably wouldn't code the
getKeyMethodMap method as it's illustrated in the Javadoc (i.e. create a new map
for each invocation). I'd be inclined to do something like:

private static final Map KEY_METHOD_MAP;
static {
  Map m = new HashMap(2);
  m.put("button.add", "add");
  m.put("button.delete", "delete");
  KEY_METHOD_MAP = Collections.unmodifiableMap(m);
}

protected Map getKeyMethodMap() {
  return KEY_METHOD_MAP;
}

Quoting Mick.Knutson@ubsw.com:

> I am trying to find a clever way to externalize the values for the
> getKeyMethodMap()?
> I do not want to hard-code map.put( "form.button.add", "add" );
> If there is anyone who has come up with a better way and would be willing to
> share, I would be very appreciative.
> 
> -------------------------
> Thank You 
> Mick Knutson 
> Sr. Designer - Project Trust 
> aUBS AG, Financial - Zürich 
> Office: +41 (0)1/234.42.75 
> Internal: 48194 
> Mobile: 079.726.14.26 
> -------------------------

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org