Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update component at change of page on primefaces datagrid with pagination

I have a datagrid with pagination. When I change the page I want to update some components in the page, but I don't know how to get the event. Some code:

<p:panelGrid id="buttons">
  <p:commandLink value="Link1" action="#{myBean.method1}" disabled="#{myBean.boolean1}" />
  <p:commandLink value="Link2" action="#{myBean.method2}" disabled="#{myBean.boolean2}" />
</p:panelGrid>
<p:dataGrid var="myVar" paginator="true" value="#{myBean.listOfObjects}">
  ...
  ...
</p:dataGrid>

I want something like update="buttons" in the dataGrid, so when the page changes, update the buttons depending on disabled="" attribute of the buttons, is it possible?

Greetings.

like image 253
Alavaros Avatar asked Jul 05 '13 11:07

Alavaros


1 Answers

Finally, instead of <p:dataGrid ... /> i used <p:dataTable ... /> with <p:ajax ... /> inside, this is my code:

<p:dataTable var="myVar" paginator="true" rows="1" value="#{myBean.listOfObjects}">
  <p:ajax event="page" update="buttons" listener="#{myBean.update}" />
  ...
  ...
</p:dataTable>

And update method:

public void update(PageEvent event) {
  int var = event.getPage();
  ...
  (update components values of dataTable and buttons using var)
  ...
}
like image 134
Alavaros Avatar answered Nov 13 '22 03:11

Alavaros