Example: I create the page something like this (PF 3.0M3):
Code: Select all
<h:form>
<h:outputLabel for="col1" value="col1 search term"/><h:inputText value="#{backingBean.criteria.col1}"/>
<p:commandButton id="criteria_find" value="SEARCH" update="@form"/>
<p:commandButton actionListener="#{backingBean.resetCriteria}" id="criteria_reset" value="RESET" update=":find_results_table" />
<p:dataTable id="find_results_table"
lazy="true"
paginator="true"
rows="5"
rowsPerPageTemplate="5,10,15"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
value="#{backingBean.dataModel}"
var="record"
selectionMode="multiple"
selection="#{backingBean.selectedItems}"
rendered="#{!backingBean.criteria.isEmpty}"
>
<p:column headerText="Column1"><h:outputText value="#{record.number}"/></p:column>
<p:column headerText="Column2"><h:outputText value="#{record.name}"/></p:column>
</p:dataTable>
</h:form>
Code: Select all
private Criteria criteria;
private LazyDataModel<MyEntity> model;
@PostConstruct
public void init() {
model = new LazyDataModel<MyEntity>() {
@Override
public List<MyEntity> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
return findEntityService.find(pageSize, first, criteria, MyEntity.class); //filters are not used, criteria act like filters in the service. Sorting is not an option.
}
};
model.setRowCount(findAccountService.getRowCount(criteria, MyEntity.class));
}
public Object getDataModel() {
return model;
}
When the user hits the RESET button I clear the search criteria on the backing bean and want the data table to be re-rendered again.
* How can I code this so that hitting my FIND or REFRESH commandButton will cause the data model to refresh? The update="@form" and update=":find_results_table" don't work; I've heard mention of some client-side API on the DataTable for refreshing but I don't know how to call it.
Thanks for the help!