jsf 2 - To do ajax refresh of JSF/primefaces datatable -
i trying jsf/primefaces ajax update on datatable on click of command link using deleting records.on clicking command link database supdated datatable doesn't refreshed if use update="@form" attribute.any guidance on how solve problem helpful.
my jsf code snippet row editable datatable contain few columns state,region below
<h:form id="lpcform"> <div id="content"> <p:commandlink id="cmdlinkdelete" value="delete" ajax="true" action="#{lpcbean.deleterecords}" update="lpcdatatable" /> <p:datatable var="lpcdata" id="lpcdatatable" widgetvar="lpctable" value="#{lpcbean.lpcidlist}" selection="#{lpcbean.selectedrows}" editable="true" scrollable="true" scrollwidth="1110" scrollheight="330" styleclass="datatable" resizablecolumns="true"> <p:ajax event="rowedit" listener="#{lpcbean.onedit}" /> <p:ajax event="roweditcancel" listener="#{lpcbean.oncancel}" /> <p:column selectionmode="multiple" style="width:15px" /> <p:column headertext="lpc id" style="width:20px"> <h:outputtext value="#{lpcdata.lpcid}" /> </p:column> <p:column headertext="region" style="width:40px"> <p:celleditor> <f:facet name="output"> <h:outputtext value="#{lpcdata.region}" /> </f:facet> <f:facet name="input"> <h:selectonemenu value="#{lpcdata.region}"> <f:selectitems value="#{lpcbean.regions}" /> </h:selectonemenu> </f:facet> </p:celleditor> </p:column> <p:column headertext="state" style="width:15px"> <p:celleditor> <f:facet name="output"> <h:outputtext value="#{lpcdata.homestate}" /> </f:facet> <f:facet name="input"> <h:selectonemenu value="#{lpcdata.homestate}"> <f:selectitems value="#{lpcbean.mainstates}" /> </h:selectonemenu> </f:facet> </p:celleditor> </p:column> . . . <p:column style="width:10px"> <p:roweditor /> </p:column> </p:datatable> </div> </h:form>
the variable lpcidlist of type of class implements datamodel.
below managed bean snippet contains deleterecords method.managed bean of requestscoped
public string deleterecords() { system.out.println("inside delete records"); system.out.println("selected rows length:"+ selectedrows.length); for(lpc itemselect:selectedrows) { string lpcid=itemselect.getlpcid(); jdbcconnection jdbcconnection=new jdbcconnection(); connection=jdbcconnection.getjdbcconnection(); try{ preparedstmt=connection.preparestatement("delete lpc lpcid=?"); preparedstmt.setstring(1, lpcid); preparedstmt.execute(); } catch(exception e) { e.printstacktrace(); } } return null; }
the variable selectedrows selection attribute of datatable
the method getlpcfields fetches data database
public void getlpcfields() { try { jdbcconnection jdbcconnection =new jdbcconnection(); connection=jdbcconnection.getjdbcconnection(); system.out.println("connected database"); selectstmt1 = connection.createstatement(); resultset rs1 = selectstmt1.executequery("select * lpc order lpcid"); while(rs1.next()){ lpcitems.add(new lpc(rs1.getstring("lpcid"),rs1.getstring("name_first"),rs1.getstring("name_last"),rs1.getstring("email_address"),rs1.getstring("region"), rs1.getstring("homestate"),rs1.getstring("profitcenter"),rs1.getstring("active_lpc"),rs1.getstring("name"))); } selectstmt2=connection.createstatement(); resultset rs2=selectstmt2.executequery("select * tbl_state"); while(rs2.next()) { mainstates.add(rs2.getstring("state")); } selectstmt3=connection.createstatement(); resultset rs3=selectstmt3.executequery("select * tbl_regional_managers"); while(rs3.next()) { regions.add(rs3.getstring("location")); } selectstmt4=connection.createstatement(); resultset rs4=selectstmt4.executequery("select * yesno order yesno_key desc"); while(rs4.next()) { activelpcs.add(rs4.getstring("description")); } } catch (exception e) { e.printstacktrace(); } { try { connection.close(); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
xtreme biker's response correct (h/t). need clear wrapped data in lpcidlist. depending on how implemented code, need populate new list or remove item existing list. can use setwrappeddata()
method of listdatamodel
.
Comments
Post a Comment