dynamic columns with nested Lists don't work

UI Components for JSF
Post Reply
jsfRocks
Posts: 7
Joined: 19 Apr 2011, 19:55
Location: Germany

19 Apr 2011, 23:56

Hello,

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>
Bean

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;
}
Wrapper

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;
    }
}
Regards
jsfRrocks
---
Primefaces 2.2.1 / JSF 2 / JBoss 6

SergioS
Posts: 1
Joined: 27 Apr 2011, 09:04

27 Apr 2011, 09:10

<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>
Have u found a solution or any workaround for this? is it a bug or something?
PD:You can do it just like this in icefaces whit no problems (except a bad rendering on the columns header)

sandhyagokhale
Posts: 1
Joined: 14 Apr 2012, 18:49

25 Apr 2012, 05:09

I am too facing same problem with primefaces 3.2, while using nested list in p:columns
java.lang.NullPointerException
at org.primefaces.component.datatable.DataTableRenderer.encodeColumnsHeader(DataTableRenderer.java:417)
at org.primefaces.component.datatable.DataTableRenderer.encodeThead(DataTableRenderer.java:574)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:246)


Has this been resolved by anyone?

dincojava
Posts: 1
Joined: 21 Aug 2012, 01:18

21 Aug 2012, 01:26

I have the same problem. Help please?

Code: Select all

   
<p:dataTable var="tableLine" value="#{testBean.lines}" >
	<p:columns value="#{tableLine.cells}" var="tableCell" columnIndexVar="colIndex">
		<f:facet name="header">  
			column -"#{colIndex}"
		</f:facet>  
		#{tableCell.value}  
	</p:columns>  
</p:dataTable>

asw
Posts: 59
Joined: 01 May 2012, 15:40

21 Aug 2012, 07:19

The example is a bit different, have a look at it: http://www.primefaces.org/showcase-labs ... olumns.jsf

In there, you access the outer list directly, but give it a "cell" index that is contained in an object stored in the list iterated over in p:columns.
Primefaces 3.3, JBoss 7.1.1, Mojarra 2.1.7
Eclipse 4.2.0, JDK 1.6.0_31, PostGreSQL 9.1
Windows XP SP3, Google Chrome 19

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 18 guests