I have web application in which I am using JSF + Primefaces for UI. I am facing difficulty in applying dirty checks on web pages specially when working with AJAX calls like AJAX call on rowSelect event of datatable.
Following is the exact scenario in which I want to apply dirty checks with AJAX call. Following are the components which I am using in my web page.
1) I have one dataTable which is populated by bean named 'companyBean' (Having attributes for companies)
<p:dataTable id="basic" var="company" value="#{companyInfoBean.companyList}"
rowKey="#{company.id}"
selection="#{companyInfoBean.selectedCompany}" selectionMode="single">
<p:ajax event="rowSelect" update=":customerDataForm:customerDataFields" />
<p:column id="modelHeader">
<f:facet name="header">
<h:outputText value="Company Name" />
</f:facet>
<h:outputText value="#{company.companyName}" />
</p:column>
more columns....
</p:dataTable>
As depicted above on row selected (AJAX Call) I update the values in the form on the bottom of the page
<h:form id="customerDataForm">
<p:panel id="customerDataFields">
<p:panelGrid >
<p:row>
<p:column>
<h:outputLabel for="companyname" value="Company Name " />
</p:column>
<p:column>
<p:inputText id="companyname" value="#{companyInfoBean.selectedCompany.companyName}" label="Company Name" />
</p:column>
more columns...
<p:row>
<p:column colspan="2" style="text-align:right">
<p:commandButton value="Save" actionListener="#{companyInfoBean.updateCompany}"
update=":customerDataForm:customerDataTable"/>
</p:column>
<p:column colspan="2" style="text-align:left">
<p:commandButton value="Undo" />
</p:column>
</p:row>
In above form user can Edit the values that is updated on the rowSelect on datatable.
Now I want a dirty check on the form on the rowSelection on the datatable i.e. if there are some unsaved changes on form that user used be prompted in spite of execution of AJAX call of rowSelect..
Basically what I can understand from this scenario.. that I need some conditional based AJAX calls rather then straightforward. Or I have to use some jQuery stuff to get dirty checks implemented.