Date: 2004-04-24T12:30:39
Editor: 131.191.40.91 <>
Wiki: Apache Struts Wiki
Page: StrutsCatalogMappedBeans
URL: http://wiki.apache.org/struts/StrutsCatalogMappedBeans
no comment
New Page:
StrutsCatalog: '''Provide a mapped bean that can be nested in in <bean:write>.'''
April 24, 2004
This !BeanMap class provides you with a bean that allows you to access map values
using <bean:write>. Assume that you have the following code somewhere:
{{{
!BeanMap beanMap1 = new !BeanMap();
!BeanMap beanMap2 = new !BeanMap();
beanMap2.setProperty("world","Hello, World!");
beanMap1.setProperty("map",beanMap2);
}}}
And, assume that you have set your beanMap1 in some scope on your website, e.g.
session.setAttribute("test",beanMap1). Now, you can access the entry in beanMap1 as
follows:
{{{
<bean:write name="test" property="map(map).map(world)"/>
}}}
This will output:
{{{
Hello, World!
}}}
Also, cf. ["StrutsCatalogInstrumentableForms"],["StrutsCatalogVariableScreenFields"],
and http://jakarta.apache.org/struts/faqs/indexedprops.html
{{{
public class BeanMap implements Map {
private Map map;
public BeanMap() {
int size = 89;
this.map = Collections.synchronizedMap(new HashMap(size));
}
public void setMap(Map map) {
this.map = map;
}
public Map getMap() {
return this;
}
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 map.toString(); }
} ///;-)
}}}
-- Michael !McGrady
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]