jsf - Primefaces update table after on-cell editing -
i have data table on-cell editing feature, , want update data table show modified record apply them different style class.
here problems:
- if not update data table when oncelledit event fires, records correctly updated, cannot see applyed style class modified rows.
- if update data table when oncelledit event fires , use return key update value, works fine, , can see applied style class modified rows.
- if update data table when on-cell edit event fires , use mouse clic update value (clicking on row or on cell within same row), first value updated correctly; when trying update other values, oncelledit event triggers before can insert new value, event triggers newvalue=oldvalue, subsequent changes.
the xhtml page:
<h:form id="frm_tbl_riv"> <p:datatable id="tbl_rilevazioni" var="rilevazione" value="#{rilevazioni.rilevazioni}" widgetvar="tbl_rilevazioni_id" editable="true" editmode="cell" scrollable="true" scrollheight="350" rowkey="#{rilevazione.idrilevazione}" selectionmode="single" selection="#{rilevazioni.selezionata}"> <p:ajax event="rowselect" update=":tview:frm_tbl_riv:popup_rilevazioni" /> <p:ajax event="celledit" listener="#{rilevazioni.oncelledit}" update=":tview:frm_btn_riv" /> <!-- update=":frm_btn_riv :frm_tbl_riv" --> <p:ajax event="contextmenu" listener="#{rilevazioni.onrilevazioneselezionata}" update="@this" /> <p:column headertext="#{msg['rilevazione']}" width="130"> <f:facet name="header"> <h:outputtext value="#{msg['rilevazione']}" /> </f:facet> <h:outputtext value="#{rilevazione.descrilevazione}" id="descril" /> </p:column> <p:column headertext="#{msg['valore']}" styleclass="#{rilevazioni.ismodificata(rilevazione) ? 'modificata' : ''}" width="30"> <h:outputtext value="#{rilevazione.valore}" rendered="#{!rilevazioni.ismodificabile(rilevazione)}" /> <p:celleditor rendered="#{rilevazioni.ismodificabile(rilevazione)}"> <f:facet name="output"> <h:outputtext value="#{rilevazione.valore}" /> </f:facet> <f:facet name="input"> <p:inputtext value="#{rilevazione.valore}" label="#{msg['valore']}"> </f:facet> </p:celleditor> </p:column> </p:datatable> </h:form>
and managed bean (view scoped):
@managedbean(name = "rilevazioni") @viewscoped public class gestionerilevazionibean implements serializable { // ... public void oncelledit(celleditevent event) { facescontext context = facescontext.getcurrentinstance(); facesmessage msg = null; object nuovovalore = event.getnewvalue(); object vecchiovalore = event.getoldvalue(); int = event.getrowindex(); rilevazionegiornaliera r = rilevazioni.get(i); r.setidutente(userbean.getuserid()); if (!nuovovalore.equals(vecchiovalore)) { try { rilevazioniservice.getinstance().updaterilevazionegiornaliera(r); modificate.add(r); } catch (throwable ex) { // ... } } } public boolean ismodificata(rilevazionegiornaliera riv) { return modificate.contains(riv); } public boolean ismodificabile(rilevazionegiornaliera rilevazione) { // logic return true; } }
if use:
update=":frm_btn_riv :frm_tbl_riv"
for on-cell edit event, obtain behaviour specified on point 2 , 3. same @form or @parent.
i have founded solution update style class modified cell after oncelledit event fires.
data table:
<p:ajax event="celledit" listener="#{rilevazioni.oncelledit}" oncomplete="handlerilevazionicelledit(xhr, status, args);" /> // ... // within cell editor <p:inputtext id="rilevazionicelleditinputtext" value="#{rilevazione.valore}" label="#{msg['valore']}" />
javascript:
<script> function handlerilevazionicelledit(xhr, status, args) { var modelinput = $('#parentid:' + args.rowindex + '\\:rilevazionicelleditinputtext'); var cell = modelinput.parent().parent().parent(); cell.addclass('modificata'); } </script>
managed bean, @ end of oncelledit() event:
requestcontext requestcontext = requestcontext.getcurrentinstance(); requestcontext.addcallbackparam("rowindex", event.getrowindex());
Comments
Post a Comment