Bonjour,
Je dispose d'une Datatable initialement remplie avec des enregistrements depuis la base de données. Pour chaque ligne il existe une colonne ACTION contenant un seul bouton pour le moment qui sert à la supression.
Dans un premier temps, la suppression d'un élément s'effectue correctement mais après lorsque j'essaie de supprimer un deuxième élément une exception qui s’élève :
javax.faces.el.EvaluationException: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Et lorsque j'essaie de déboguer la méthode de suppression je trouve que le premier élément supprimé est celui qui s'appelle avec la méthode ce qui déclenche l'exception ci-dessous
Code de la vue :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <p:dataTable var="egressSystem" value="#{egressSystemBean.egressSystemList}" widgetVar="EgressSystem_Table" rows="10" paginator="true" rendered="true"
emptyMessage="#{msg['NoRecordFound']}" id="EgressSystem_Table" filteredValue="#{egressSystemBean.filteredEgressSystemList}" paginatorPosition="bottom"
rowsPerPageTemplate="5,10,20">
<f:facet name="header">
<div align="left">
<p:outputPanel>
<p:inputText id="globalFilter" onkeyup="PF('EgressSystem_Table').filter()" class="width_150p" placeholder="#{msg['SearchFields']}" />
</p:outputPanel>
</div>
</f:facet>
<p:column headerText="#{msg['Brand']}" sortBy="#{egressSystem.brand}" filterBy="#{egressSystem.brand}" filterStyle="display:none" filterMatchMode="contains" priority="2">
<h:outputText value="#{msg[egressSystem.brand]}" />
</p:column>
<p:column headerText="#{msg['Model']}" sortBy="#{egressSystem.model}" filterBy="#{egressSystem.model}" filterStyle="display:none" filterMatchMode="contains">
<h:outputText value="#{msg[egressSystem.model]}" />
</p:column>
<p:column headerText="#{msg['IpAdress']}" sortBy="#{egressSystem.ipAdress}" filterBy="#{egressSystem.ipAdress}" filterStyle="display:none" filterMatchMode="contains"
priority="2">
<h:outputText value="#{egressSystem.ipAdress}" />
</p:column>
<p:column headerText="#{msg['Port']}" sortBy="#{egressSystem.port}" filterBy="#{egressSystem.port}" filterStyle="display:none" filterMatchMode="contains" priority="3">
<h:outputText value="#{egressSystem.port}" />
</p:column>
<p:column headerText="#{msg['Door']}" filterBy="#{egressSystem.door}" filterStyle="display:none" filterMatchMode="contains" priority="4">
<h:outputText value="#{egressSystem.door.designation}" />
</p:column>
<p:column headerText="#{msg['Status']}" class="status">
<span class="#{egressSystem.status}"> </span>
</p:column>
<p:column headerText="#{msg['Actions']}">
<p:outputPanel>
<p:commandButton action="#{egressSystemBean.update()}" icon="ui-icon-pencil" ajax="false" title="#{msg.Modify}">
<f:setPropertyActionListener value="#{egressSystem}" target="#{egressSystemBean.egressSystem}" />
</p:commandButton>
<p:commandButton icon="ui-icon-trash" action="#{egressSystemBean.delete}" title="#{msg.Delete}" update="EgressSystem_Form:EgressSystem_Table">
<f:setPropertyActionListener value="#{egressSystem}" target="#{egressSystemBean.egressSystem}" />
<p:confirm header="#{msg.Confirmation}" message="#{msg.MsgDeleteEgressSystem}" icon="ui-icon-alert" />
</p:commandButton>
</p:outputPanel>
</p:column>
</p:dataTable>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="#{msg.Oui}" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="#{msg.Non}" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog> |
Classe contenant la méthode de suppression :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
| @Controller("egressSystemBean")
@Scope("session")
public class EgressSystemBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(EgressSystemBean.class);
@Autowired
private IEgressSystemService egressSystemService;
@Autowired
private IDateRefreshService dateRefreshService;
private EgressSystem egressSystem = new EgressSystem();
private List<EgressSystem> egressSystemList;
private List<EgressSystem> filteredEgressSystemList;
private boolean renderCreate = true;
private String dateLastUpdate;
private DateRefresh dateRefresh;
private Door doorIn;
private Door doorOut;
private FacesContext facesContext;
private HttpSession session;
private ArrayList<Device> deviceList = new ArrayList<Device>();
private Device brand;
public EgressSystemBean() {
facesContext = FacesContext.getCurrentInstance();
session = (HttpSession) facesContext.getExternalContext().getSession(false);
}
@PostConstruct
public void init() {
setRenderCreate(false);
egressSystemList = new ArrayList<>();
egressSystemList = egressSystemService.findAll(EgressSystem.class);
egressSystem = new EgressSystem();
getLastDateOfRefrech();
if ((EgressSystem) session.getAttribute("egressSystem") != null) {
egressSystem = (EgressSystem) session.getAttribute("egressSystem");
}
}
public String create() {
renderCreate = true;
egressSystem = new EgressSystem();
brand = null;
session.removeAttribute("egressSystem");
return Constants.CREATE;
}
public String refresh() {
try {
egressSystemList = egressSystemService.refreshEgressSystem(egressSystemList);
if (dateRefresh == null) {
dateRefresh = new DateRefresh();
dateRefresh.setTableName(TableName.T_EGRESS_SYSTEM);
}
dateRefresh.setDateRefresh(new Date());
dateRefresh = dateRefreshService.saveOrUpdateService(dateRefresh);
dateLastUpdate = DateUtils.returnDateTime(dateRefresh.getDateRefresh());
} catch (DeviceAccessControlException exception) {
AccessControlError.showError(MessageUtils.getMessage(exception.getMessage()));
} catch (AccessControlException exception) {
AccessControlError.showError(MessageUtils.getMessage(exception.getMessage()));
}
return Constants.LIST;
}
private void getLastDateOfRefrech() {
dateRefresh = dateRefreshService.findDateRefreshByTable(TableName.T_EGRESS_SYSTEM);
if (dateRefresh != null) {
dateLastUpdate = DateUtils.returnDateTime(dateRefresh.getDateRefresh());
}
}
public String update() {
renderCreate = false;
brand = egressSystem.getBrand();
session.setAttribute("egressSystem", egressSystem);
return Constants.CREATE;
}
public void reset() {
egressSystem = new EgressSystem();
brand = null;
}
public String cancel() {
init();
return Constants.LIST;
}
public String delete() {
try {
egressSystemService.deleteService(egressSystem);
logger.debug("INFO level message: Suprema Egress Systems deleted " + egressSystem.toString());
init();
} catch (ConstraintViolationException e) {
AccessControlError.showError(MessageUtils.getMessage(Constants.ERR_DELETE_ELEMENT));
}
return Constants.LIST;
}
public String save() {
egressSystem.setBrand(brand);
egressSystemService.saveOrUpdateService(egressSystem);
logger.debug("INFO level message: Egress System saved " + egressSystem.toString());
init();
return Constants.LIST;
}
public void setTimeClock() {
if (egressSystem.getModel().equals(Model.IN01)) {
egressSystem.setTimeClock(true);
}
}
public EgressSystem getEgressSystem() {
return egressSystem;
}
public void setEgressSystem(EgressSystem egressSystem) {
this.egressSystem = egressSystem;
}
public List<EgressSystem> getEgressSystemList() {
return egressSystemList;
}
public void setEgressSystemList(List<EgressSystem> egressSystemList) {
this.egressSystemList = egressSystemList;
}
public List<EgressSystem> getFilteredEgressSystemList() {
return filteredEgressSystemList;
}
public void setFilteredEgressSystemList(List<EgressSystem> filteredEgressSystemList) {
this.filteredEgressSystemList = filteredEgressSystemList;
}
public String getDateLastUpdate() {
return dateLastUpdate;
}
public void setDateLastUpdate(String dateLastUpdate) {
this.dateLastUpdate = dateLastUpdate;
}
public ArrayList<Device> getDeviceList() {
deviceList.clear();
deviceList.add(Device.SUPREMA);
deviceList.add(Device.ZK);
return deviceList;
}
public void setDeviceList(ArrayList<Device> deviceList) {
this.deviceList = deviceList;
}
public ArrayList<Model> getModelList() {
return Model.getModelByDevice(brand);
}
public DateRefresh getDateRefresh() {
return dateRefresh;
}
public void setDateRefresh(DateRefresh dateRefresh) {
this.dateRefresh = dateRefresh;
}
public Door getDoorIn() {
return doorIn;
}
public void setDoorIn(Door doorIn) {
this.doorIn = doorIn;
}
public Door getDoorOut() {
return doorOut;
}
public void setDoorOut(Door doorOut) {
this.doorOut = doorOut;
}
public boolean isRenderCreate() {
return renderCreate;
}
public void setRenderCreate(boolean renderCreate) {
this.renderCreate = renderCreate;
}
public IEgressSystemService getEgressSystemService() {
return egressSystemService;
}
public void setEgressSystemService(IEgressSystemService egressSystemService) {
this.egressSystemService = egressSystemService;
}
public IDateRefreshService getDateRefreshService() {
return dateRefreshService;
}
public void setDateRefreshService(IDateRefreshService dateRefreshService) {
this.dateRefreshService = dateRefreshService;
}
public Device getBrand() {
return brand;
}
public void setBrand(Device brand) {
this.brand = brand;
}
} |
Partager