I created this example of JSF button with question dialog:
<!-- hidden button -->
<h:commandButton id="deleterow" value="HiddenDelete" action="#{AccountProfileTabGeneralController.saveData}" style="display:none" update="growl">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
<!-- edit button -->
<h:button style="position:absolute; bottom:12px; right:12%;" rendered="#{AccountProfileTabGeneralController.editable}" styleClass="lbimage" value=" Save Account " onclick="editdialog(this, 'Do you want to save the changes?'); return false;" />
I use this JS to display the dialog:
function editdialog(button, a){
$("<div />", {
text: a
}).dialog({
width: 600,
buttons: {
"Ok": function() {
$("#form\\:deleterow").click();
$(this).dialog("close");
button.value = "Processing...";
button.disabled = true;
},
"Cancel": function(event) {
$(this).dialog("close");
event.preventDefault();
button.value = "Save Account";
button.disabled = false;
}
}
});
}
But for some reason then I click OK button the button is disabled and it’s not working maybe the id of the form is not correct. I use this <h:form id="general">
How I can fix the problem? And also how I can use the code in forms with different id’s?
If you have the form’s id as “general”, the jQuery selector should probably be
but as you pointed out, you may have different forms, so that selector is very specific.
I would think you’d want something like:
What this does is find the first parent
formelement of the button that initiated theeditDialogfunction, then find any element inside of that form that has anidthat ends with “deleterow”. This should work, since theidof that element will be something like “form_id:deleterow”.