To Create a Dynamic table from a Java Collections like Array list and Hash maps. The simple way is we need to create the table data based on the collection modal.
Create a simple bean that will return the students list wrapped in the collection model.
The column iterator will be based on the number of columns of table.
Sample Code
Create a simple bean that will return the students list wrapped in the collection model.
public void generateCollectionModel(){ this.model = new SortableModel(addRowsToCollectionModel(columnNames)); } public List<Map> addRowsToCollectionModel(List<String> columnNames){ List<Map> rows= new ArrayList<Map>(); for (StudentClass studentData:studentList) { Map newRow = new HashMap(); newRow.put("Id", studentData.getId()); newRow.put("Name", studentData.getName()); newRow.put("Grade", studentData.getGrade()); newRow.put("Address", studentData.getAddress()); newRow.put("Rank", studentData.getRank()); rows.add(newRow); } return rows; }And created a simple page with adf table and column iterator.
<af:table varStatus="rowStat" summary="table" value="#{pageFlowScope.DynamicTable.collectionModel}" rows="#{pageFlowScope.DynamicTable.collectionModel.rowCount}" rowSelection="none" contentDelivery="immediate" var="row" rendered="true" id="t1"> <af:forEach items="#{pageFlowScope.DynamicTable.columnNames}" var="name"> <af:column sortable="true" sortProperty="#{name}" rowHeader="unstyled" headerText="#{name}" inlineStyle="width:100px;" id="c1"> <af:activeOutputText value="#{row[name]}" id="aot1"/> </af:column> </af:forEach> </af:table>
The column iterator will be based on the number of columns of table.
Sample Code