I am using primefaces command button with following code.
<p:commandButton id="filereconSubmit" value="#{msg.button_submit}" oncomplete="completeWork();" onclick="clearPagination();filereconWidget.clearFilters();" update="filereconModalDialog" action="#{reconController.register}" styleClass="content-data" />
above code works fine. but when I add javascript validate function, oncomplete is not fired.
onclick="clearPagination();filereconWidget.clearFilters();return validate(#{reconciliationController.reconSearchDays})"
Javascript code looks like below.
function completeWork() {
PrimeFaces.clearSelection();
$('th.ui-sortable-column').removeClass('ui-state-active').find('.ui-sortable-column-icon').removeClass('ui-icon-triangle-1-n ui-icon-triangle-1-s');
showDatatable();
}
function validate(search_days){
var isValid = false;
var dateformat = "d-MMM-yyyy";
var sdate = Date.parse(document.getElementById('filerecon:startdate_input').value, dateformat);
var edate = Date.parse(document.getElementById('filerecon:enddate_input').value, dateformat);
if(sdate == null || edate == null){
alert("Enter both Start Date and End Date");
} else if (sdate > edate) {
alert("Select an End Date after the Start Date");
} else if((edate-sdate)>(1000*60*60*24*search_days)){
alert("Search is limited to "+search_days+" days. So End Date should not be more than "+search_days*24+" hours from Start Date.");
} else {
isValid = true;
}
return isValid;
}
I have gone through JSF execution order of events but couldn't figure out what's wrong there???