I am trying to integrate the sweet alert plugin in a boto in JSF to show a presentable confirmation window, the problem is that pressing the button opens the sweet alert but still executes the action of the controller without taking into account the confirmation and refreshes the page, that is to say that the sweet alert if it leaves, but refreshes the page and therefore it closes.
This is the code I use in the javascipt
function dialog() {
event.preventDefault();
swal({
title: "Are you sure?",
text: "Your will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false},
function (isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
return true;
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
return false;
}
});
}
And this is the code on the JSF page
<h:commandLink id="boton" onclick="return dialog()" action="#{productosController.refrescar()}">
<i class="fa fa-pencil"></i>
</h:commandLink>
Someone who can give me your help?