I have a dataTable with dynamic content and in the cells some tags I use prevent me from using methods with parameters so I looked out for a solution with simple Setters & Getters.
My first approach was to iterate over to independent lists but the action going on in the cells forced not to do this (as described above).
So I decided to build a own wrapper for each cell to access the data easily, but it seems to be a problem to nest a list into a list of wrappers.
-> java.lang.NullPointerException org.primefaces.component.datatable.DataTableRenderer.encodeColumnsHeader(DataTableRenderer.java:293)
Here is simple example of what I did (don't care about the meaning of the output it's just for demonstration purpose of course my table is much more complicated):
XHTML
Code: Select all
<p:dataTable var="wrapperElement" value="#{testBean.mainList}">
<p:column>
<f:facet name="header">some Text</f:facet>
<h:outputText value="#{wrapperElement.name}" />
</p:column>
<p:columns var="innerStuff" value="#{wrapperElement.innerList}" columnIndexVar="colIndex">
<f:facet name="header">
<h:outputText value="#{innerStuff.bytes}" />
</f:facet>
<h:outputText value="#{innerStuff}" />
</p:columns>
</p:dataTable>
Code: Select all
public class testBean {
public List<MyWrapper> getMainList(){
List<MyWrapper> mainList = new ArrayList<MyWrapper>();
MyWrapper w1 = new MyWrapper("one");
w1.getInnerList().add("InnerOne(1)");
w1.getInnerList().add("InnerTwo(1)");
MyWrapper w2 = new MyWrapper("two");
w2.getInnerList().add("InnerOne(2)");
w2.getInnerList().add("InnerTwo(2)");
MyWrapper w3 = new MyWrapper("three");
w3.getInnerList().add("InnerOne(3)");
w3.getInnerList().add("InnerTwo(3)");
mainList.add(w1);
mainList.add(w2);
mainList.add(w3);
return mainList;
}
Code: Select all
public class MyWrapper {
private String name;
private List<String> innerList;
public MyWrapper(String name) {
this.name = name;
this.innerList = new ArrayList<String>();
}
public List<String> getInnerList() {
return innerList;
}
public String getName() {
return name;
}
}