jsf - Refreshing PrimeFaces form element dataTable (code details provided) -
i have search form. after clicking on search button data refreshes, datatable columns not (columns refreshed on second button click). apparently doing wrong. dynamic column code inspired primefaces showcase
myform.xhtml:
<h:form id="my_form"> #{mybean.initbean()} ... <h:panelgrid id="main"> <h:panelgrid id="buttons"> <p:commandbutton id="submitsearch" value="#{msg['button.execute']}" actionlistener="#{mybean.submitsearch}" update="resultpanel"/> </h:panelgrid> </h:panelgrid> <h:panelgrid id="resultpanel" border="0"> <p:datatable id="resulttable" var="result" value="#{mybean.searchresults}"> <p:columns value="#{mybean.columns}" var="column" columnindexvar="colindex"> <f:facet name="header"> <h:outputtext value="#{column.header}" /> </f:facet> <h:outputtext value="#{result[column.property]}" /> </p:columns> </p:datatable> </h:panelgrid> </h:form>
i've called column calculation method createcolumns()
mybean.initbean()
, mybean.submitsearch()
same result (i see works correctly debugger).
@managedbean("mybean") @scope(value = "session") public class mybean { private arraylist<hashmap<string,object>> searchresults; private list<columnmodel> columns; ... public void initbean() { ... createcolumns(selecteddates); } public void submitsearch() { ... arraylist<hashmap<string, object>> results = prprepository.getsearchresultbyparams(searchparams); createcolumns(selecteddates); } private void createcolumns(arraylist<string> selecteddates){ columns = new arraylist<columnmodel>(); columns.add(new columnmodel("name", "name")); columns.add(new columnmodel("amount", "amount")); (int = 0; < selecteddates.size(); i++) { columns.add(new columnmodel(selecteddates.get(i), "date" + i)); } setcolumns(columns); } public list<columnmodel> getcolumns() { return columns; } public void setcolumns(list<columnmodel> columns) { this.columns = columns; } }
additional information: using:
- oracle's implementation of jsf 2.1 specification
- javaserver pages api 2.2
- springframework 3.1.2 (incl. spring-context, spring-web)
- glassfish javax.annotation 3.1.1
the problem columns calculted once time in org.primefaces.component.datatable.datatabe
public list<uicolumn> getcolumns() { // if(columns == null) { columns = new arraylist<uicolumn>(); facescontext context = getfacescontext(); char separator = uinamingcontainer.getseparatorchar(context); for(uicomponent child : this.getchildren()) { if(child instanceof column) { columns.add((uicolumn) child); } else if(child instanceof columns) { columns uicolumns = (columns) child; string uicolumnsclientid = uicolumns.getclientid(context); uicolumns.updatemodel(); /* missed code */ for(int i=0; < uicolumns.getrowcount(); i++) { dynamiccolumn dynacolumn = new dynamiccolumn(i, uicolumns); dynacolumn.setcolumnkey(uicolumnsclientid + separator + i); columns.add(dynacolumn); } } } // } return columns; }
you comment , overwrite class file, or find datatable object , setcolumns null inside createcolumns method
Comments
Post a Comment