2

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}" />

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Eugene
  • 27
  • 5
  • Possible duplicate of [Send additional parameter to Ajax event listener](https://stackoverflow.com/questions/39143601/send-additional-parameter-to-ajax-event-listener) – Jasper de Vries Feb 15 '18 at 15:32
  • I do not use a p:dataTable. I use a p:dataGrid. I do not have to add an action listener to row selected. I have to pass additional parameters when a page number button(or next page button) will be pressed. – Eugene Feb 15 '18 at 18:23
  • If you cannot be more precise in which sort of parameter, differences for the buttons, etc, otherwise the duplicate **is** a duplicate... – Kukeltje Feb 15 '18 at 18:44
  • I do not have to click a row. I have to click a next page button. A user clicks a next page button and load() function is called(I use lazy="true"), but I need to send some data to a managed bean before load is called. I have attached a picture. Please look at it. – Eugene Feb 15 '18 at 19:16

1 Answers1

0

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.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • You cannot add parameters to that method, but you can set them in a bean which you use inside the load method. I do it all the time for passing a 'multi-tenant' field that needs to be used in the queries in the load method. Works great. – Kukeltje Feb 16 '18 at 11:50
  • @Kukeltje Sure thing. We are doing the same thing more or less, when constructing the lazy model we provide a base query builder. I never had the need to change anything on pagination though. – Jasper de Vries Feb 16 '18 at 11:58
  • I have used event="page" and f:attribute. It is works. I have got some parameters in my listener method. Thanks a lot. – Eugene Feb 16 '18 at 13:15