tag. All this requires is some
additional Bean-style method names that invoke existing non-Bean-style
methods. The Collection methods operate on the collection of entries in
the map.
Note: Can't get it to work. For some reason, all the lines I could think
to try like:
iterate zero times. What am I doing wrong?
Note: May not be necessary anyhow, since forEach is supposed to iterate
the entries of Maps even without this class, according to:
http://www.theserverside.com/discussions/thread.tss?thread_id=35477
and:
http://www.ibm.com/developerworks/java/library/j-jstl0318/
So, why is it not working for me? When I iterate over the same
object, in the same page with the following Java code instead, it
works fine:
<%
for (Iterator i = userIdAccessAttrMapBean.getIterator(); i.hasNext();)
{
Map.Entry entry = (Map.Entry) i.next();
String key = (String)entry.getKey();
AccessAttrBean attr = (AccessAttrBean)entry.getValue();
String role = attr.getName();
logutil.log("JSP Username = " + key);
logutil.log("JSP Role = " + role);
}
%>
Usage:
- The typical scenario for using this class is:
<% myMapBean.setMap(myMap); // No way to do this line in JSP? %>
${entry.key.name} |
${entry.value.name} |
${entry.key.name} |
${entry.value.name} |
${key.name} |
${value.name} |
${myMapBean.containsKey}
${myMapBean.containsValue}
${myMapBean.hashCode}
${myMapBean.size}
${myMapBean.toString}
${myMapBean.empty}
${myMapBean.toArray}
${myMapBean.map}
Assumptions:
Effects:
- None.
Anticipated Changes:
Notes:
Implementation Notes:
- Cannot implement both interfaces Map and Collection because they
have incompatible versions of remove(Object). See the comments
at remove(Object) below for details.
Portability Issues:
Revision History:
$Log$
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry |
Field Summary |
private Map |
m_map
|
private static long |
serialVersionUID
This number identifies the version of the class definition, used for
serialized instances. |
m_map
private Map m_map
serialVersionUID
private static final long serialVersionUID
- This number identifies the version of the class definition, used for
serialized instances. Be sure to increment it when adding/modifying
instance variable definitions or making any other change to the class
definition. Omitting this declaration causes a compiler warning for
any class that implements java.io.Serializable.
- See Also:
- Constant Field Values
MapBean
public MapBean()
- Default Constructor.
Note: This constructor with no params is required for the class to be a
Java Bean, so that it can be accessed via .
With no params, this constructor cannot initialize the wrapped Map.
Therefore, m_map can't be a "blank final", so we initialize it to
a Map to support all the methods that use it,
Also, we have a setter for it, so the caller can pass in an entire
map at once, like they can do with the non-default constructor.
We have a getter also for completeness, even though it is really
not necessary since this class itself is a Map that could always
be used by any caller in place of the encapsulated Map.
MapBean
public MapBean(Map map)
- Constructor.
- Parameters:
map
- The Map to encapsulate.
getMap
public Map getMap()
- Return the encapsulated Map.
- Returns:
- The encapsulated Map.
setMap
public void setMap(Map map)
- Set the encapsulated Map.
- Parameters:
map
- The Map to encapsulate.
equals
public boolean equals(Object obj)
- Calls
Map.equals(Object)
- Specified by:
equals
in interface Map
- Overrides:
equals
in class Object
hashCode
public int hashCode()
- Calls
Map.hashCode()
- Specified by:
hashCode
in interface Map
- Overrides:
hashCode
in class Object
toString
public String toString()
- Calls
AbstractMap.toString()
- Overrides:
toString
in class Object
clear
public void clear()
- Calls
Map.clear()
- Specified by:
clear
in interface Map
isEmpty
public boolean isEmpty()
- Calls
Map.isEmpty()
- Specified by:
isEmpty
in interface Map
size
public int size()
- Calls
Map.size()
- Specified by:
size
in interface Map
containsKey
public boolean containsKey(Object arg0)
- Calls
Map.containsKey(Object)
- Specified by:
containsKey
in interface Map
containsValue
public boolean containsValue(Object arg0)
- Calls
Map.containsValue(Object)
- Specified by:
containsValue
in interface Map
entrySet
public Set entrySet()
- Calls
Map.entrySet()
- Specified by:
entrySet
in interface Map
get
public Object get(Object key)
- Calls
Map.get(Object)
- Specified by:
get
in interface Map
keySet
public Set keySet()
- Calls
Map.keySet()
- Specified by:
keySet
in interface Map
put
public Object put(Object arg0,
Object arg1)
- Calls
Map.put(Object, Object)
- Specified by:
put
in interface Map
putAll
public void putAll(Map arg0)
- Calls
Map.putAll(Map)
- Specified by:
putAll
in interface Map
values
public Collection values()
- Calls
Map.values()
- Specified by:
values
in interface Map
add
public boolean add(Object arg0)
- Calls
Set.add(Object)
on the Set returned by
Map.entrySet()
addAll
public boolean addAll(Collection arg0)
- Calls
Set.addAll(Collection)
on the Set returned by
Map.entrySet()
contains
public boolean contains(Object arg0)
- Calls
Set.contains(Object)
on the Set returned by
Map.entrySet()
containsAll
public boolean containsAll(Collection arg0)
- Calls
Set.containsAll(Collection)
on the Set returned by
Map.entrySet()
iterator
public Iterator iterator()
- Calls
Set.iterator()
on the Set returned by
Map.entrySet()
remove
public Object remove(Object arg0)
- Calls
Set.remove(Object)
on the Set returned by
Map.entrySet()
- Specified by:
remove
in interface Map
removeAll
public boolean removeAll(Collection arg0)
- Calls
Set.removeAll(Collection)
on the Set returned by
Map.entrySet()
retainAll
public boolean retainAll(Collection arg0)
- Calls
Set.retainAll(Collection)
on the Set returned by
Map.entrySet()
toArray
public Object[] toArray()
- Calls
Set.toArray()
on the Set returned by
Map.entrySet()
toArray
public Object[] toArray(Object[] arg0)
- Calls
Set.toArray(Object[])
on the Set returned by
Map.entrySet()
getHashCode
public int getHashCode()
- Calls
hashCode()
getToString
public String getToString()
- Calls
toString()
getSize
public int getSize()
- Calls
size()
getContainsKey
public boolean getContainsKey(Object arg0)
- Calls
containsKey(Object)
getContainsValue
public boolean getContainsValue(Object arg0)
- Calls
containsValue(Object)
getEntrySet
public Set getEntrySet()
- Calls
entrySet()
getKeySet
public Set getKeySet()
- Calls
keySet()
getValues
public Collection getValues()
- Calls
values()
getIterator
public Iterator getIterator()
- Calls
iterator()
getToArray
public Object[] getToArray()
- Calls
toArray()