PrimeFaces – actions not firing in last rows of dataGrid


Have you been at your wit’s end trying to work out why your action just won’t fire? Have you exhausted BalusC’s list of potential reasons?

Does it happen to be just the last couple of buttons that don’t work, and you’re using PrimeFaces’s dataGrid?

This happens when your row size is set up strangely, given the number of columns you’ve set your dataGrid to. The trick to remember here is that rows refers to data rows, not table rows.

There is an issue where if there are not enough rows set to evenly fill up the number of columns you’ve set the grid to, but there is enough data, then the final spots are still filled up but any actions bound to them will not fire.

This also causes the issue where the dataGrid appears to be generating duplicate items if you’re using pagination – the extra rows that are rendered out are rendered again on the next page, as that’s where they’re meant to be.

Quick Fix

The quick fix is just to set the number of rows correctly, to fill the number of columns you have. As long as the number of rows is a multiple of the number of columns (eg, 2 columns, 6 rows) you should be fine. Perhaps they’ll fix this in a future version of Primefaces to not render the extra items, but your grid will look strange in that case without the columns being filled.

Recreating this issue

Here’s a minimal recreation if anyone wants to see this issue. As an XHTML page,

And as the backing bean,

You’ll see here the final two buttons do not fire an action.

Tagged with: , , , ,
Posted in Java
2 comments on “PrimeFaces – actions not firing in last rows of dataGrid
  1. bennyboy says:

    You just saved me.
    may god bless you 🙏

Leave a Reply