I want to pass additional parameters when a paginator button is clicked. The data looks like this:
<p:dataGrid
var="citem"
value="#{group.lazyItemGroup}"
paginator="true"
rows="4"
lazy="true"
columns="2"
layout="grid"
id="items"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="6,12,16"
>
...
...
...
</p:dataGrid>
Can I use something like this?
<p:inputText id="id" value="#{group.id}" type="hidden" />
or
<f:attribute name="id" value="#{group.id}" />
If you are referring to the load
method of the LazyDataModel
you have implemented, then no, you cannot simply add parameters to that method.
Since you were talking about "when a paginator button is clicked", I assumed you had a page
event listener in place. Apparently you haven't, so add that to your p:dataGrid
:
<p:dataGrid ...>
<p:ajax event="page"
listener="#{yourBean.yourListener}"/>
</p:dataGrid>
And to your bean:
public void yourListener(PageEvent event) {
...
}
In your listener you can pass anything to your custom lazy data model instance, and pick that up in the load
method. You could also add a <f:attribute .../>
to your data grid component, which can be read in the listener method (see Send additional parameter to Ajax event listener).
Please note that you can get the page from the page event:
event.getPage();
This might help in determining what additional data to set.