I'm using primefaces.
I have a form and a dataTable with a lazyModel, in the dataTable I show the results found after searching with the input data.
I need to do a couple of validations in my bean side whenever I press the "Search" button, and in the case where a validation fails I don't want to re-render my dataTable because if I do it, then it will launch a new query to the database with the wrong input values and it will lose the previous results.
<h:form>
<!-- Here I have a bunch of inputTexts -->
<h:commandButton value="Search">
<p:ajax process="@form" update="@form" listener="#{myBean.search}"/>
</h:commandButton>
<p:dataTable id="myResults" var="item" value="#{myBean.lazyModel}" lazy="true">
<!-- Rows of my dataTable -->
</p:dataTable>
<h:form>
In my bean I have something like the next code (of course it is more complicated than that, otherwise I will create a JSF validator:
public void search() {
// test validation
if (myService.validateData(this.value1, this.value2, this.value3) and this.value4 == false) {
MuMessageUtils.setFacesErrorMessage("validation.error.1");
// I don't want to refresh my dataTable
}
// everything ok
else {
// I want to refresh my dataTable
// do more stuff with the data
}
}
Can I detect whenever the validation fails and stop the update process from the ajax event attached to the Search button, or even not process at all the form if the validation fails?
Thanks.