Reputation: 1674
I have a problem which I don't know how to solve. I have a form which I use to display data and also to edit data.
<!-- New Network button -->
<h:button style="position:absolute; bottom:25px; right:265px;" styleClass="buttonImage" value="New Network" outcome="/Network/NewNetwork.xhtml" rendered="#{not bean.editable}"/>
<!-- Edit button -->
<h:commandButton style="position:absolute; bottom:25px; right:150px;" styleClass="buttonImage" onclick="this.disabled = true;" value=" Edit Network " rendered="#{not bean.editable}" action="#{bean.editNetwork(true)}" >
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
<!-- Save Changes button -->
<h:commandButton style="position:absolute; bottom:25px; right:150px;" rendered="#{bean.editable}" styleClass="buttonImage" value=" Save Changes " onclick="editdialog(this, 'Do you want to save the changes?');
return false;" />
<!-- Hidden Edit button -->
<h:commandButton id="editdata" value="HiddenDelete" action="#{bean.saveData}" style="display:none">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
<!-- Cancel button -->
<h:commandButton style="position:absolute; bottom:25px; right:65px;" styleClass="buttonImage" value=" Cancel " rendered="#{bean.editable}" action="#{bean.initDBData}" >
<f:ajax render="@form"></f:ajax>
</h:commandButton>
I use this JavaScript in order to confirm edit of data:
// Question Dialog for edit panel
function editdialog(button, a) {
jQuery("<div />", {
text: a
}).dialog({
width: 600,
buttons: {
"Ok": function() {
jQuery(button).closest("form").find("[id$=editdata]").click();
//$("form\\:deleterow").click();
jQuery(this).dialog("close");
button.value = "Processing...";
button.disabled = true;
},
"Cancel": function(event) {
jQuery(this).dialog("close");
event.preventDefault();
button.value = "Save Changes";
button.disabled = false;
}
}
});
}
But after checking server longs data the Java method saveData
is never called by the JavaScript. I'm missing something which I cannot find. Can you help me to find my mistake, please.
EDIT:
The problem is here:
<!-- Hidden Edit button -->
<h:commandButton id="editdata" value="HiddenDelete" style="position:absolute; bottom:25px; right:650px;" action="#{bean.saveData}" rendered="#{bean.editable}">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
When I click the button the form is not submitted and the the Java method savedata
is not called.
Upvotes: 0
Views: 107
Reputation: 2114
I think there are quotes missing in the jQuery selector:
jQuery(button).closest("form").find("[id$='editdata']").click();
Upvotes: 1