Problem: For the below provided code snippet, the page reloads on click of h:commandButton
if f:ajax
onevent has function name provided as value, however for the same, if it has the function declaration provided as onevent value, it works as expected.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"" >
<h:head>
<h:outputStylesheet library="blue" name="style/style.css" />
<h:outputScript library="script" name="jquery-1.8.0.min.js" />
<script>
function jq(myid) {
return "#" + myid.replace( /(:|\.|\[|\]|,)/g, "\\\\$1" );
}
function confirmDelete(data){
if(data.status == "success") {
$("#confirmDelete").show();
$(jq("licenseForm:buttons")).hide();
}
return false;
}
</script>
</h:head>
<h:body styleClass="bodyForm">
<div class="content">
<h:form id="licenseForm">
<fieldset id="confirmDelete">
<h:panelGroup>
<h:panelGrid columns="2">
<h:selectOneMenu value="#{bean.deleteReason}">
<f:selectItems value="#{metadata.deleteReasons}" />
</h:selectOneMenu>
</h:panelGrid>
</h:panelGroup>
</fieldset>
<h:panelGroup id="buttons" layout="block">
<h:commandButton value="Delete" styleClass="button">
<f:ajax onevent="confirmDelete" />
</h:commandButton>
</h:panelGroup>
</h:form>
</div>
</h:body>
</html>
JSF Version: Mojarra JSF Implementation 2.2.12
Server: Apache Tomcat 8.0.24