Ok below is the code that i have. Here we read a map from a JAVA object and populate columns based on the key and values of the map. The Java object map is of the form
HashMap<HashMap<String, Object>>
.
The required table will have columns equal to number of outer hashmap. The row count will be equal to number of Sting/Objects in the inner hashmap.
Following is the code which generates table. As described above, the number of columns in the table will depend on the values in the java object. The problem we are facing is, if the value in hashmap is above 10 then PDH generation resuls in loss of data.
<table style="font-family:Arial;font-size:xx-small;color:black" width="100%" border="0" cellspacing="0" cellpadding="0">
#set ($allLegs = $ConfirmationObject.getAllLegs())
#set ($i = 1)
<tr>
<td valign="top" width="30%"> </td>
#foreach($legSzie in $allLegs.keySet())
<td valign="top" width="30%" align="left"><b>Leg $i</b></td>
#set ($i=$i+1)
#end
<tr><td></td></tr>
<td valign="top" width="10%" align="right"> </td>
</tr>
<td colspan="1">
<table style="font-family:Arial;font-size:xx-small;color:black" width="100%" border="0" cellspacing="0" cellpadding="0">
#set ($map = $ConfirmationObject.getLegMap(1))
#foreach($key in $map.keySet())
<tr>
<td valign="top" width="60%">$key </td>
</tr>
#end
</table>
</td>
#foreach($legString in $allLegs.keySet())
<td colspan="1">
<table style="font-family:Arial;font-size:xx-small;color:black" width="100%" border="0" cellspacing="0" cellpadding="0">
#set ($legMap = $allLegs.get($legString))
#foreach($legKey in $legMap.keySet())
<tr>
<td >$legMap.get($legKey)</td>
</tr>
#end
</table>
</td>
#end
</table>
Expectation: Is it possible to have the data split into different tables when ever the column value reaches more than 3?
so for example consider a scenario where the table looks like
LEG 1 LEG 2 LEG 3 LEG 4 LEG 5
A 12 13 14 15 16
B 12 13 14 15 16
C 12 13 14 15 16
D 12 13 14 15 16
E 12 13 14 15 16
How can we split this like
LEG 1 LEG 2 LEG 3
A 12 13 14
B 12 13 14
C 12 13 14
D 12 13 14
E 12 13 14
LEG 4 LEG 5
A 15 16
B 15 16
C 15 16
D 15 16
E 15 16
#set ($allLegs = $ConfirmationObject.getAllLegs())
#set ($columns = $allLegs.keySet())
#set ($maxCols = 3)
#set ($groups = ($columns.size() + $maxCols - 1)/$maxCols)
#set ($lastGroup = $groups - 1)
#foreach ($group in [0..$lastGroup])
#if($group >0 )
<br>
<br>
#end
<table style="font-family:Arial;font-size:xx-small;color:black" width="100%" border="0" cellspacing="0" cellpadding="0">
#set ($allLegs = $ConfirmationObject.getAllLegs())
#set ($i = (($group*$maxCols)+1))
#set ($groupLegs = $ConfirmationObject.getGrouplLegSet($group, $maxCols))
<tr>
<td valign="top" width="30%"> </td>
#foreach($legSzie in $groupLegs.keySet())
<td valign="top" width="30%" align="left"><b>Leg $i</b></td>
#set ($i=$i+1)
#end
<td></td>
<td valign="top" width="10%" align="right"> </td>
</tr>
<td colspan="1">
<table style="font-family:Arial;font-size:xx-small;color:black" width="100%" border="0" cellspacing="0" cellpadding="0">
#set ($map = $ConfirmationObject.getLegMap(1))
#foreach($key in $map.keySet())
<tr>
<td valign="top" width="60%">$key </td>
</tr>
#end
</table>
</td>
#foreach($legString in $groupLegs.keySet())
<td colspan="1">
<table style="font-family:Arial;font-size:xx-small;color:black" width="100%" border="0" cellspacing="0" cellpadding="0">
#set ($legMap = $allLegs.get($legString))
#foreach($legKey in $legMap.keySet())
<tr>
<td >$legMap.get($legKey)</td>
</tr>
#end
</table>
</td>
#end
</table>
#end
Here we wrote a java method getGrouplLegSet($group, $maxCols). The method would just return sub-set of hashmap based on the group and maxCols. So for example if the group is 0 then values from 0 till 2 will be returned, if group value is 1 then sub map from 3 till 5 will be returned and so on..