spauny
spauny

Reputation: 5096

Primefaces nested dataTable render problems

I'm using Primefaces with JSF2.0. I have a nested dataTable which I want to be rendered only if some boolean flag(safeToLoadDataTable) is true, but this doesn't happen and when I open the page record.columnList throws NullPointerException because obviously it isn't yet initialized. I fill those lists after a search button from the same page it's pressed.

My Code:

<p:panel rendered="#{enastrSearch.safeToLoadDataTable}">
                <p:dataTable id="tableData" var="record" value="#{enastrSearch.recordsList}" >
                    <p:column>
                        <p:dataTable var="column" value="#{record.columnList}">
                            <p:column>
                                <f:facet name="header">
                                    Name
                                </f:facet>
                                <h:outputText value="#{column.columnName}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    Value
                                </f:facet>
                                <h:outputText value="#{column.columnValue}" />
                            </p:column>
                        </p:dataTable>
                    </p:column>
                </p:dataTable>
            </p:panel>

Why doesn't the rendered attribute work? And I was also wondering if using nested dataTable is OK. Thank you!

UPDATE:

My flag looks like this:

private boolean safeToLoadDataTable;

    public boolean isSafeToLoadDataTable() {
        if(recordsList!=null && !recordsList.isEmpty()){
            safeToLoadDataTable = true;
        }else{
            safeToLoadDataTable = false;
        }


        return safeToLoadDataTable;
    }

Anyway I've tried even with return false and still the panel is rendered.

Upvotes: 0

Views: 3162

Answers (1)

BalusC
BalusC

Reputation: 1108722

when I open the page record.columnList throws NullPointerException because obviously it isn't yet initialized

You should not do anything else in getColumnList() than just returning the list property. The getter should look like exactly this:

public List<Column> getColumnList() {
    return columnList;
}

It should not contain any other code. Any initialization of this property should be done in the bean's (post)constructor or action(listener) methods.


Unrelated to the concrete problem, I'd suggest to just use empty keyword in EL instead of that clumsy boolean getter.

<p:panel rendered="#{not empty enastrSearch.recordsList}">

Upvotes: 1

Related Questions