I think the id attribute of beans is not a wrapper object (Integer id;
). Have a look at doc page of Map.
Text from JavaDoc
Note: great care must be exercised if
mutable objects are used as map keys.
The behavior of a map is not specified
if the value of an object is changed
in a manner that affects equals
comparisons while the object is a key
in the map. A special case of this
prohibition is that it is not
permissible for a map to contain
itself as a key. While it is
permissible for a map to contain
itself as a value, extreme caution is
advised: the equals and hashCode
methods are no longer well defined on
a such a map.
Item.java
package com.me;
public class Item {
private Integer id;
private String description;
public Item() {
}
public Item(Integer id, String description) {
this.id = id;
this.description = description;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
JSP snippet
<%
HashMap<Integer, String> myMap = new HashMap<Integer, String>();
myMap.put(new Integer(1), "One");
myMap.put(new Integer(2), "Two");
myMap.put(new Integer(3), "Three");
request.setAttribute("myMap", myMap);
List<com.me.Item> list=new ArrayList<com.me.Item>();
list.add(new com.me.Item(1,"A - Desc"));
list.add(new com.me.Item(2,"B - Desc"));
list.add(new com.me.Item(3,"C - Desc"));
request.setAttribute("list", list);
%>
<c:forEach items="${list}" var="item" varStatus="status">
<c:out value="${item.description}"/>
<c:out value="${myMap[item.id]}"/>
</c:forEach>
HashMap<String, some bean>
because i tried this${applicationscope.coursesHT[anotherbean.courseC]}
to get the description of course but it didnot work but when i usec:set
andc:out
it worked !! :) thanks – Botch