简体   繁体   English

Primefaces嵌套的dataTable呈现问题

[英]Primefaces nested dataTable render problems

I'm using Primefaces with JSF2.0. 我在JSF2.0中使用了Primefaces。 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. 我有一个嵌套的dataTable,仅当某些布尔标志(safeToLoadDataTable)为true时才要呈现,但这不会发生,并且当我打开页面record.columnList时会抛出NullPointerException,因为显然它尚未初始化。 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. 我也想知道使用嵌套dataTable是否可以。 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. 无论如何,我什至尝试使用return false仍然渲染面板。

when I open the page record.columnList throws NullPointerException because obviously it isn't yet initialized 当我打开页面record.columnList时抛出NullPointerException,因为显然它尚未初始化

You should not do anything else in getColumnList() than just returning the list property. 您不应该在getColumnList()做任何其他事情,而只是返回list属性。 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. 此属性的任何初始化都应该在bean的(后)构造函数或action(侦听器)方法中完成。


Unrelated to the concrete problem, I'd suggest to just use empty keyword in EL instead of that clumsy boolean getter. 具体问题无关 ,我建议只在EL中使用empty关键字,而不要使用笨拙的布尔型getter。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM