Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Action method of backing bean called multiple times instead of once.

630109Sep 15 2009 — edited Sep 17 2009
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>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 15 2009
Added on Sep 15 2009
8 comments
1,974 views