Primefaces 嵌套 dataTable 渲染问题
我正在使用 Primefaces 和 JSF2.0。 我有一个嵌套的 dataTable,只有在某个布尔标志(safeToLoadDataTable)为 true 时才需要渲染它,但这不会发生,当我打开页面时 record.columnList 会抛出 NullPointerException,因为显然它尚未初始化。我在按下同一页面的搜索按钮后填充这些列表。
我的代码:
<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>
为什么渲染的属性不起作用?我还想知道使用嵌套数据表是否可以。 谢谢你!
更新:
我的标志看起来像这样:
private boolean safeToLoadDataTable;
public boolean isSafeToLoadDataTable() {
if(recordsList!=null && !recordsList.isEmpty()){
safeToLoadDataTable = true;
}else{
safeToLoadDataTable = false;
}
return safeToLoadDataTable;
}
无论如何,我已经尝试过,即使返回 false,面板仍然呈现。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了返回列表属性之外,您不应该在
getColumnList()
中执行任何其他操作。 getter 应该如下所示:它不应该包含任何其他代码。此属性的任何初始化都应在 bean 的(后)构造函数或操作(侦听器)方法中完成。
与具体问题无关,我建议在 EL 中使用
empty
关键字,而不是那个笨拙的布尔 getter。You should not do anything else in
getColumnList()
than just returning the list property. The getter should look like exactly this: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.