Hari Haran wrote:
Hi,This is a pretty well-worn area, Hari. If you would like to make the whole deal safe, and are using Struts 1.2, you might try http://wiki.apache.org/struts/StrutsCatalogInstrumentableForms , or:
In recent past I have been working with struts Map-backed Action Form. It can accept any number of HTML form parameters without declaring each field as accessors or in an external XML file.
This seems to be a good approach , as I don't need to create a new ActionForm for my data entry screens any more.
I would like to know groups experience with Map-backed Action Forms.
1. can we consider this option for production grade code. 2. Does it have any hidden performance overhead.
-Hari Haran
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
public class BeanMapForm extends ActionForm implements Map {
private Map map;
public BeanMapForm() { int size = 89; this.map = Collections.synchronizedMap(new HashMap(size)); }
public void setMap(Map map) { this.map = map; }
public Map getMap() { return map; }
public void setProperty(Object key, Object value) { map.put(key,value); }
public Object getProperty(Object key) { return map.get(key); }
public void clear() { map.clear(); } public boolean containsKey(Object key) { return map.containsKey(key);} public boolean containsValue(Object value) { return map.containsValue(value); } public Set entrySet() { return map.entrySet(); } public boolean equals(Object object) { return map.equals(object); } public Object get(Object key) { return map.get(key); } public int hashCode() { return map.hashCode(); } public boolean isEmpty() { return map.isEmpty(); } public Set keySet() { return map.keySet(); } public Object put(Object key, Object value) { return map.put(key,value); } public void putAll(Map map) { map.putAll(map); } public Object remove(Object key) { return map.remove(key); } public int size() { return map.size(); } public Collection values() { return map.values(); } public String toString() { return "BeanMapForm[" + map.toString() + "]"; }
Michael McGrady } ///;-)
See Joshua Bloch's _Effective Java_, Item 14 (favoring composition over inheritance) for good reasons to approach things this way. This won't work with lower than 1.2 due to a need to have the commons utils distinguish between a regular map and an ActionForm map.
Michael McGrady
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]