Reputation: 173
I am using primefaces datatable to show the users with radio buttons to make selection, now when page loads, table shows page 1 by default and 25 rows per page[this is expected], what i want now is if user sets 25 rows per page[by dropdown] and goes to say 4th page and selects the user, submits the form, now when page has got refreshed , i want user to see the table with previous page(4th and not 1st) and same no. of rows per page(25 and not 10).
Pasting below my datatable. [ my bean is ViewAccessscoped].
<p:dataTable id="tableid" var="result"
styleClass="supertable top75"
paginatorTemplate="{RowsPerPageDropdown} {CurrentPageReport} {LastPageLink} {NextPageLink} {PageLinks} {PreviousPageLink} {FirstPageLink}"
value="#{bean.datamodel}"
tableStyleClass="pdatatable-table" rows="10"
rowsPerPageTemplate="10,25,50,100" paginator="true"
emptyMessage="No Users are available"
I tried setting "first" property of datatable by using below code in my bean but that din't work out, this is what i tried
added below event in xhtml
<p:ajax event="page" listener="#{bean.onPageChange}"></p:ajax>
and method to bean
public void onPageChange(PageEvent event){
pageindex=event.getPage();
final DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("loginasform:homeDataTable");
dataTable.setFirst(pageindex); }
i do receive the value in bean but it still shows the default page and rows per page.
I am new to JSF and Primefaces , please let me know if you can help here.
Upvotes: 4
Views: 6425
Reputation: 186
To restore the state of your datatable(like it was before the refresh)...
Set p:dataTable attribute multiViewState="true" (refer the demo Table State)
And yet if it doesnt seem to work, change to @ViewScoped. Also confirm the version of primefaces you are using.
Upvotes: 2