You can do it like this:
View
<h:form id="mainForm"> <p:dataTable id="locationTable" value="#{datatableBean.list}" var="item" paginator="true" widgetVar="dtVar" rows="#{datatableBean.rows}" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="1,2,3,4,5,6"> <p:column> #{item.name} </p:column> </p:dataTable> <p:remoteCommand name="persistRows" action="#{datatableBean.saveRows}" process="@this" update="rows" global="false" /> <h:outputText id="rows" value="#{datatableBean.rows}" /> <script> jQuery(document).ready(function() { dtVar.paginator.rppSelect.change(function() { persistRows([{name: 'rows', value: this.value}]); }); }); </script> </h:form>
Bean
import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; @ManagedBean @SessionScoped public class DatatableBean implements Serializable { private int rows; private List<SimpleBean> list; @PostConstruct public void setup() {
The strategy here is to extend the onchange event associated with the html select tags displayed with paginator. To make this easier, I set wigetVar to datatable ( dtVar ), knowing that the clientide api gives us both choices through dtVar.paginator.rppSelect .
Now, in order to be able to send a value for those selected for the managed bean, we can use remoteCommand. Using the remoteCommand component, we can send javascript parameters to the managed one. I called remoteCommand as persistRows , and by calling it, I specified additional parameters using the template required by the component: [{name: 'rows', value: this.value}] ([{name: 'nameOfTheVariable ", value:' valueOfTheVariable '}]).
Now you can do whatever you want with this rows attribute.
source share