java - Dirty Checks: JSF + Primefaces application? -


i have web application in using jsf + primefaces ui. facing difficulty in applying dirty checks on web pages specially when working ajax calls ajax call on rowselect event of datatable.

following exact scenario in want apply dirty checks ajax call. following components using in web page.

1) have 1 datatable populated bean named 'companybean' (having attributes 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) update values in form on bottom of 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 values updated on rowselect on datatable.

now want dirty check on form on rowselection on datatable i.e. if there unsaved changes on form user used prompted in spite of execution of ajax call of rowselect..

basically can understand scenario.. need conditional based ajax calls rather straightforward. or have use jquery stuff dirty checks implemented.

there different ways can implement this. here few (i prefer method 3 if popup's ok):

method 1:

a) use copy of selectedcompany eg, editcompanybean backing bean customerdatafields.
b) add "listener" ajax event can check editcompanybean null values before setting selectedcompany's values. if fails can growl message , block copy. note: can use override switch override (b)
c) on save of editcompanybean initialize null values fields.

method 2:

a) in set statement selectedcompany check if bean has value populated. throw warning message if populated , skip edit.
b) have user click save or reset on customerdatafields before proceeding.
note: clear selectedcompany after each save or reset of customerdatafields

method 3:

a) put customerdatafields in modal popup dialog. set user has save or reset before proceeding.
b) ajax event popup above modal dialog. can use button popup well.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -