在primefaces中编辑单元格后,表格将消失(数据也不会保存)



我在页面上有一个输入字段和一个表。每当字段中的数字发生变化(ajax侦听器更改事件)时,我都希望行数相应地发生变化。

我将表指向Backingbean中的一个Arraylist,并使用它的大小。

但是,当我编辑表格中的值并按enter键时,表格会消失,只有当我再次更改字段值时才会重新出现。

另外,在调试模式下,我看到支持arraylist总是有空值。

Bean代码如下:

@ManagedBean(name = "bean")
@ViewScoped
public class TestBean {
private List<String> hostnames = new ArrayList<String>();
private int copiesQuantityJustCopy;
public int getCopiesQuantityJustCopy() {
return copiesQuantityJustCopy;
}
public void setCopiesQuantityJustCopy(int copiesQuantityJustCopy) {
this.copiesQuantityJustCopy = copiesQuantityJustCopy;
}
public List<String> getHostnames() {
return hostnames;
}
public void setHostnames(List<String> hostnames) {
this.hostnames = hostnames;
}
public void onUpdateCount() {
int hostnamesCount = hostnames.size();
System.out.println("delta = " + hostnamesCount + " - " + copiesQuantityJustCopy);
int delta = hostnamesCount - copiesQuantityJustCopy;
if (delta > 0)
for (int i = 1; i < delta; i++)
hostnames.remove(delta);
if (delta < 0)
for (int i = 0; i < -delta; i++)
hostnames.add("");
}
}

视图代码:

<h:form id="form1">
<p:inputMask mask="9?99" maxlength="3" placeHolder=" " value="#{bean.copiesQuantityJustCopy}">
<p:ajax event="change" listener="#{bean.onUpdateCount()}" update=":form1:hostnamesTable" />
</p:inputMask>
<p:outputPanel id="hostnamesTable" rendered="true">
<p:dataTable value="#{bean.hostnames}" var="hostname" 
id="hostnames" editable="true" editMode="cell">
<p:ajax event="cellEdit" update=":form1:hostnamesTable" process="@this" />
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{hostname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{hostname}" style="width:96%" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>

我认为我的答案对@Anton没有帮助,但它可能对另一个面临同样问题的"堆叠者"有帮助

我的问题类似(当cellEdit事件完成时,dataTable会消失)。在我的案例中,原因是ajax执行的表更新。由于在监听器被解雇后我真的不需要更新表,所以我只是删除了更新属性,现在一切都对我很好。

最新更新