MapKey mapKey = new MapKey(reqId, name, status);
LinkedHashMap<Object, List<Dashboard>> map = new LinkedHashMap<>();
Mapkey Class:
public class MapKey {
private Integer id;
private String name;
private Integer status;
public MapKey(Integer id, String name,Integer status) {
this.id = id;
this.name = name;
this.status=status;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
//All getters and setters
POJO CLASS:
public class Dashboard {
int requestId;
String loginUser;
int price;
int status;
public int getrequestId() {
return requestId;
}
public void setrequestId(int requestId) {
requestId= requestId;
}
//All getters and setters
JSP code:
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="1" style="text-align: center;">
<TR>
<c:forEach var="entry" items="${map}">
<TH>${entry.key}</TH>
</c:forEach>
</TR>
//iterate again
<c:forEach var="entry" items="${map}">
//entry.value is ArrayList so we can iterate with c:forEach
<c:forEach var="headers" items="${entry.value}">
<TR>
<TD>${headers}</TD>
</TR>
</c:forEach>
</c:forEach>
</TABLE>
Input:
MapKey [reqid=123, name=A,status=1]:[Dashboard [reqid=123, NAME=A, PRICE=5,STATUS=2],Dashboard [reqid=123, NAME=A, PRICE=10,STATUS=3],...,..]
MapKey [reqid=456, name=B,status=2]:[Dashboard [reqid=456, NAME=B, PRICE=20,STATUS=3],Dashboard [reqid=456, NAME=B, PRICE=25,STATUS=2],...,..]
Expected Output:
123 A 1 ///Table header
123 A 5 2
123 A 10 3
//N no of rows
456 B 2 ///Table header
456 B 20 3
456 B 25 2
//N no of rows
I have a Map where key is an Object and value is List.Arraylist comprises of rows of each unique reqid as objects. In the map, keys are my table header and the value in the map is the table data for that header.Keys depends on the data from sql.It can be vary as per data.I want to display each key as table header and all its related data as rows of the table.I have written code in jsp to create table for each key.I am newbie in java development,so that is is what I could write.I need help to achieve the expected output.