Reputation: 27
How to use Struts2 tag to traversal a Map<Course,String>
in JSP.
Course
is a class. It has three attributes. They are String coursename
, int courseid
, String courseType
. I use Struts2 in my project. The Action returns the Map<Course,String>
to JSP.
And I use
<s:iterator value="cmap" status="st">
<tr><td>
<s:iterator value='key'><s:property value="key.coursename"/></s:iterator> </td>
<td><s:property value='value'></s:property></td></tr>
</s:iterator>
It can print the right String value in JSP. But it cannot print the Course Type data! How to solve it? I am a novice.
Upvotes: 1
Views: 6905
Reputation: 24396
You do not need second iterator to get Course
data. Just use key
to get your values.
<s:iterator value="cmap">
<tr>
<td><s:property value="key.coursename"/></td>
<td><s:property value="value"/></td>
</tr>
</s:iterator>
BTW a map with a key which is custom object is very annoying thing.
Upvotes: 4