Go Go Gnome
the website of Sander Kooijmans

JSF ace:dataTable sorts its data in the field of the backing bean

Posted: September 13, 2021

A true story: we build a web application with JSF. We use ace:dataTable to let the user sort and filter the table rows.

One table was sorted by default, so without user interaction. Inside this table, the user could change a dropdown field. We use partial submit so that a value change listener could update the value in the database.

What we did not expect was that when one the value of one dropdown is changed, sometimes other dropdowns changes too. Only on screen, not in the database. So after refreshing the page, everything looks fine again. But this bug is very confusing to our users.

After many hours of debugging I discovered that the problem was caused by the value change listener. It would not only change one record in the database. It would also refresh the field in the backing bean with an updated list of rows from the database.

What I discovered is that when the ace:dataTable sorts its rows, it sorts the list in the backing bean. When our value change listener updated this list, it would put the rows in a different order than the order that the ace:dataTable sorted them. And the ace:dataTable cannot deal with changing the order of this list during the application life cycle (restore view, apply request values, process events, ..., render response).

To fix this bug, we now sort the new value of the list in the same order as the old list before assigning the new list to the backing bean.