Properties props = new Properties();
InputStream is = this.getClass().getClassLoader().getResourceAsStream
("my.properties");
props.load(is);
return props; // since its just a Map also
Matt Raible wrote:
Pardon my ignorance, but your comment about Properties.load got me interested. However, I can't seem to figure out how to shorten my code (guess I haven't done much work with Properties files). I found this example:http://www.javaworld.com/javaworld/javatips/jw-javatip125.html But it seems to just increase the number of lines ;-) Matt-----Original Message-----
From: Erik Hatcher [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 18, 2002 7:06 AM
To: Struts Developers List
Subject: Re: LookupDispatchAction - loading values from a properties file
Matt,
This looks reasonable. Generally speaking changing a button mapping would involve new code, so a recompile is necessary, but as you mention you are mapping multiple buttons to the same method.
Although I'd caution against using LookupDispatchAction unless you really have forms that have multiple submit buttons to submit that same form data. If you're simply mapping multiple non-form-related actions into one class, then I'd argue this is not the right approach.
Erik
p.s. It looks like you might be able to save a few lines of code by using the Properties.load method instead of going through a ResourceBundle. ???
Matt Raible wrote:
I was thinking of loading a properties file for myKeyMethodMap in a
subclass of LookupDispatchAction.project had 18
So this:
* Provides the mapping from resource key to method name
*
* @return Resource key / method name map
*/
protected Map getKeyMethodMap()
{
Map map = new HashMap();
map.put("button.add", "add");
map.put("button.cancel", "cancel");
map.put("button.copy", "copy");
map.put("button.save", "save");
map.put("button.edit", "edit");
return map;
}
Could be replaced with the following psuedo code:
protected Map getKeyMethodMap()
{
Map map = new HashMap();
ResourceBundle methods = ResourceBundle.getBundle("LookupMethods");
Enumeration keys = methods.getKeys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
map.put(key, methods.getString(key));
}
return map;
}
Is there any reason(s) why I shouldn't do this? I think it allows greater flexibility for development - so I don't have to re-compile this class everytime I want map a new method. My last
different mappings for the the different button names - where many mapped to the same method.
Thanks,
Matt
--
To unsubscribe, e-mail: <mailto:struts-dev-> [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]>