Hi,
My backing bean has an action method called "saveEquipmentList" that's called when a "Save" button is clicked. The problem is, this method gets executed twice every time the button is clicked so data gets peristed twice, db triggers get executed twice, etc., it's really pretty annoying. I've put the bean method's code and the JSF command button below, notice that there's a check for FacesContext.getRenderResponse() that I put in for debugging, the code doesn't get executed at all if I leave the FacesContext.getRenderResponse() in, sure, you're saying "So what's you point", no point, just thought I'd explain why the check is in there.
Thanks,
Alex
public synchronized String saveEquipmentList() throws Exception {
// Order is very important.
if (FacesContext.getCurrentInstance().getRenderResponse()) {
System.out.println("GOT RENDER RESPONSE... XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
try {
loadEquipmentCodesMap(); // Loads map from equip_code_ids in the DB.
updateEquipCodesMap(); // Updates total for objcode/type to sum of equipment items for that objcode/type.
saveEquipmentCodes(); // Saves to equipment_codes table.
loadEquipmentCodesMap();
updateDataList();
savedataList();
updateTotals();
loadEquipmentList();
}
catch (Exception e) {
setErrMessage("Error saving equipment: " + e.getMessage());
return "success";
}
}
/*
}else{
//facesContext.getCurrentInstance().renderResponse();
}
*/
return "success";
}
<h:panelGroup id="pg54">
<h:commandButton id="save" disabled="#{(user.role == '2' and backing_equipmentScreen.viewOnly) or
(user.role == '1' and !backing_equipmentScreen.viewOnly)}"
value="Save"
action="#{backing_equipmentScreen.saveEquipmentList}"
styleClass="input"/>
</h:panelGroup>