Recently got a requirement to do generation of dynamic tables based on data output. Used jsp to perform the generation of table from data format of list of multidimensional string arrays List<String[][]>. This will enable generation of multiple tables by looping number of String[][] with the first string array as number of rows and the second string array as number of columns. The jsp code is as below.
<%
List<String[][]> processLst = new ArrayList<String[][]>();
processLst = //-- call method to get the list
String outstr = "";
int i = 0;
for (i = 0; i < processLst.size(); i++) {
String[][] outputData = processLst.get(i);
%>
<div>
<table border="1" width="450" >
<tr class="font-white">
<th bgcolor="#000000" colspan="<%=outputData[i].length %>"><%=outputData[0][0] %>
</th>
</tr>
<%
for (int rowNum = 1; rowNum < outputData.length; rowNum++) {
%>
<tr>
<%
for (int cellNum = 0; cellNum < outputData[0].length; cellNum++) {
outstr="";
if(outputData[rowNum][cellNum]!=null)
outstr = outputData[rowNum][cellNum];
%>
<td bgcolor="white">
<%=outstr %>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
</div>
No comments:
Post a Comment