I am using Primefaces 5.0 to create a dynamic datatable.
My DataObject has some required fields and a List of optional \"tupel\" (key-value pair). The optional list
java:
@Named @ViewScoped public class LiveRangeService implements Serializable { private List< Map > tableData; private List tableHeaderNames; public List> getTableData() { return tableData; } public List getTableHeaderNames() { return tableHeaderNames; } public void PlayListMB() { tableData = new ArrayList< Map >(); //Generate table header. tableHeaderNames = new ArrayList(); for (int j = 0; j < 5; j++) { tableHeaderNames.add(new ColumnModel("header "+j, " col:"+ String.valueOf(j+1))); } //Generate table data. for (int i = 0; i < 10; i++) { Map playlist = new HashMap(); for (int j = 0; j < 5; j++) { playlist.put(tableHeaderNames.get(j).key,new ColumnModel(tableHeaderNames.get(j).key,"row:" + String.valueOf(i+1) +" col:"+ String.valueOf(j+1))); } tableData.add(playlist); } } static public class ColumnModel implements Serializable { private String key; private String value; public ColumnModel(String key, String value) { this.key = key; this.value = value; } public String getKey() { return key; } public String getValue() { return value; } }
And XHTML:
header table
That's a example.