문제

Could anyone please explain me about How to iterate this map separately department and reporting to in the below example using jstl.

Map<String, List<Object>> map = new HashMap<String, List<Object>>();
    List<EmployeeDeparment> department = Emp.getEmployeeDepartment(EmployeeId);
    map.put("department", department);
    map.put("allreportingTo", allreportingTo);
    map.put("alldepartments", alldepartments);
request.setAttribute("map", map);
도움이 되었습니까?

해결책

As shown below:

<c:forEach var="entry" items="${map}">
  Key: <c:out value="${entry.key}"/>
  Value: <c:out value="${entry.value}"/>
</c:forEach>

To get list value from the map using the key as below:

${map.department}

And you can iterate over the list, as shown below:

<c:forEach items="${map.department}" var="element"> 
  <tr>
    <td>${element.deptName}</td>
  </tr>
</c:forEach>

다른 팁

try this,

List<String> list = new ArrayList<String>(map.keySet());
request.setAttribute("list", list);

<c:forEach< items="${list}" var="entry">
    <c:forEach items=${map[entry]} var="employeeDept">
        <c:out value ="${employeeDept.name}"/> 
// get some more values like this
    </c:forEach>
</c:forEach>

Your are writing

Map<String, List<Object>> map = new HashMap<String, List<Object>>();
List<EmployeeDeparment> department = Emp.getEmployeeDepartment(EmployeeId);
List<EmployeeDeparment> department = Emp.getEmployeeDepartment(EmployeeId);
map.put("department", department);

Map of key as String and value as List of Object but you are storing as value in map List of EmmployeeDeparment

So in order to get into work you nedd to change like:

Map<String,  List<EmployeeDeparment>> map = new HashMap<String,  List<EmployeeDeparment>>();
List<EmployeeDeparment> department = Emp.getEmployeeDepartment(EmployeeId);
List<EmployeeDeparment> department = Emp.getEmployeeDepartment(EmployeeId);
map.put("department", department);
and  your remain code...

and

<c:forEach items="${map}" var="m">
    <c:forEach items="${map.value}" var="list">
        ${list.id }
        ${list.name }
    </c:forEach>
</c:forEach>
<c:forEach items="${map.department}" var="dept">
     ${dept.deptName}                   
</c:forEach>

Insted of deptName take your model attribute.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top