我对primefaces dataTable有一点问题,
我在我的表中设置了一个commandButton,以便从表中删除数据
但是当我选择删除一行时,我发现它已经删除了2行而不只是一行
这是我的Bean
package com.beans;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.event.CellEditEvent;
import org.primefaces.event.RowEditEvent;
import com.bo.DiplomeBo;
import com.converter.DiplomeDataModel;
import com.model.Collaborateur;
import com.model.Diplome;
public class DiplomeBean {
public Integer idDiplome;
public String ecole;
public String typeEcole;
public String typeDiplome;
public Integer promotion;
private Set<Collaborateur> collaborateurs = new HashSet<Collaborateur>(0);
public Diplome selectedDiplome;
private DiplomeBo diplomeBo;
public Diplome getSelectedDiplome() {
return selectedDiplome;
}
public void setSelectedDiplome(Diplome selectedDiplome) {
this.selectedDiplome = selectedDiplome;
}
public Integer getIdDiplome() {
return idDiplome;
}
public void setIdDiplome(Integer idDiplome) {
this.idDiplome = idDiplome;
}
public String getEcole() {
return ecole;
}
public void setEcole(String ecole) {
this.ecole = ecole;
}
public String getTypeEcole() {
return typeEcole;
}
public void setTypeEcole(String typeEcole) {
this.typeEcole = typeEcole;
}
public Integer getPromotion() {
return promotion;
}
public void setPromotion(Integer promotion) {
this.promotion = promotion;
}
public Set<Collaborateur> getCollaborateurs() {
return collaborateurs;
}
public void setCollaborateurs(Set<Collaborateur> collaborateurs) {
this.collaborateurs = collaborateurs;
}
public void setDiplomeBo(DiplomeBo diplomeBo) {
this.diplomeBo = diplomeBo;
}
public String getTypeDiplome() {
return typeDiplome;
}
public void setTypeDiplome(String typeDiplome) {
this.typeDiplome = typeDiplome;
}
public String AddDiplome() {
Diplome diplome = new Diplome();
diplome.setEcole(getEcole());
diplome.setPromotion(getPromotion());
diplome.setTypeDiplome(getTypeDiplome());
diplome.setTypeEcole(getTypeEcole());
diplomeBo.addDiplome(diplome);
clearForm();
return "Ajout Bien Fait !!";
}
public String UpdateDiplome(Diplome dip) {
diplomeBo.updateDiplome(dip);
return "Update Bien Fait";
}
public String DeleteDiplome(Diplome diplome){
diplomeBo.deleteDiplome(diplome);
clearForm();
return "";
}
public List<Diplome> getAllDiplome() {
return diplomeBo.findAllDiplome();
}
private void clearForm() {
this.setEcole("");
this.setPromotion(0);
this.setTypeEcole("");
this.setTypeEcole("");
}
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Diplome Edited");
Integer i = ((Diplome) (event.getObject())).getIdDiplome();
Diplome d = new Diplome();
d.setIdDiplome(i);
d.setEcole(this.getEcole());
this.UpdateDiplome(d);
FacesContext.getCurrentInstance().addMessage(null, msg);
clearForm();
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Diplome Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
这是我的页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<f:view>
<h:outputLink value="Admin/default.xhtml">Go to your app</h:outputLink>
<h:form id="form">
<p:growl id="messages" showDetail="true" />
<p:dataTable var="dip" value="#{diplome.getAllDiplome()}" id="diplomeList"
editable="true">
<f:facet name="header">
In-Cell Editing
</f:facet>
<p:ajax event="rowEdit" listener="#{diplome.onEdit}"
/>
<p:ajax event="rowEditCancel" listener="#{diplome.onCancel}"
/>
<p:column headerText="ID" style="width:10%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dip.idDiplome}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{dip.idDiplome}#{diplome.idDiplome}" style="width:100%" readonly="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Ecole" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dip.ecole}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{diplome.ecole}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-trash"
title="Delete this actor"
action="#{diplome.DeleteDiplome(dip)}"
ajax="false" />
</p:column>
</p:dataTable>
</h:form>
</f:view>
</body>
</html>