添加新行时,我在数据表中遇到问题:
我想添加一个空行,但是如果我点击按钮它会添加一行,但组件仍然存在。
<p:selectCheckboxMenu>
包含旧值。
也就是说<p:selectCheckboxMenu>
的值保留了前一行的值
<p:dataTable value="#{solotionManager.customers}"
id="table" var="o"
widgetVar="50"
style="width: 100%;"
editable="true"
scrollHeight="330"
styleClass="datatable">
<p:ajax event="rowEdit" listener="#{customerBeansController2.onEdit}" update=":form1:table" process="@this"/>
<f:facet name="header">
Order List
</f:facet>
<p:ajax event="rowEditCancel" listener="#{customerBeansController2.onCancel}" update=":form1:messages"/>
<p:column>
<f:facet name="header" >
<h:outputText value="ID customer" style="width:100%"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{o.id}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{o.id}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="firstName"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{o.firstName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{o.firstName}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="lastName"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{o.lastName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{o.lastName}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="SelectManyMenu" style="width:100%"/>
</f:facet>
<p:cellEditor>
<f:facet name="input">
<p:selectCheckboxMenu value="#{solotionManager.choice}" label="Phone" converter="entrantConverter">
<f:selectItems value="#{solotionManager.listeChoice}" var="c" itemValue="#{c}" itemLabel="#{c}"/>
</p:selectCheckboxMenu >
</f:facet>
<f:facet name="output">
<p:selectCheckboxMenu value="#{solotionManager.choice}" label="Phone" converter="entrantConverter">
<f:selectItems value="#{solotionManager.listeChoice}" var="c" itemValue="#{c}" itemLabel="#{c}"/>
</p:selectCheckboxMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options">
<p:rowEditor/>
</p:column>
</p:dataTable>
public String newLine(javax.faces.event.ActionEvent actionEvent) {
this.customers.add(this.custom1);
this.custom1=new Customer();
return null;
}
添加行的按钮的代码:
<p:commandButton value="add row" actionListener="#{solotionManager.newLine}" update="table" oncomplete="addRowOnComplete()"/>
函数javascript addRowOncomplete:
<script type="text/javascript">
function addRowOnComplete() {
jQuery('.ui-datatable-data tr td').last().find('span.ui-icon-pencil').each(function(){jQuery(this).click();});
}
</script>