JSF dataTable with thousands of checkboxes - jsf

I have a dataTable on JSF that has the following column:
<ice:column style="width:25px;">
<ice:selectBooleanCheckbox value="#{historyBean.checked[mapEntry2.id]}" partialSubmit="true" id="playlist-select" style="width:25px;">
</ice:selectBooleanCheckbox>
</ice:column>
As you can see it's formed by checkboxes that are bound to an map where keys are ids and values are booleans.
It all works well pretty good. But sometimes the dataTable can have as many as a few thousand rows, and then, when a user checks or unchecks one of the checkboxes, the partialSubmit starts to get sluggish.
What I want, at the end of the day, is to perform an operation on the server on the data of each selected row. So far I'm using the partialSubmit and a map on the server to store the Ids of the selected data.
How can I make the check/uncheck operation be reflected faster on the server? Any clues?
Thank you.

Related

p:selectBooleanCheckbox *look only* shifted after adding a row to a p:dataTable

I have a p:dataTable. In this table, I have a checkbox in a column. This is the code:
<p:selectBooleanCheckbox
value="#{var.selected}"
itemLabel="#{var.description}"
/>
After I add a row and update the whole table, the selected checkboxes after the row inserted have the checks shifted up! But it's only a graphical problem! The checkboxes that now appears unchecked are yet checked, because I show other things in the row if the checkbox is selected. On the contrary, the checkbox that now appear checked do not show the additional components.
I checked the html, and the classes and attributes that make them checked disappears. But debugging the backend I see that the in the list connected to the table, after the add, all the items have the expected value.
This is a minimal reproducible example:
https://ufile.io/6a60kxpn
I don't know why, but I solved putting process="#this" to the actionButtons. If someone can explain me why, I'll accept the answer.

Editable Datatable RowKey Null

I have an editable Primefaces Datatable configured to call an onCellEdit() method when a cell is edited. Everything works great except that CellEditEvent.rowKey is always null in spite of setting it explicitly to a valid value in the Datatable declaration with 'rowKey='. The Primefaces Datatable documentation leads me to believe that I need the rowKey to get the contents of the row containing the cell being edited. I need the entire row's contents so I can compare the displayed data with the same data in the database to determine if the persisted data had been changed by another client since the Datatable was rendered, catching concurrent edits.
After reading a dozen or more posts on the rowKey being null with row-selectable Datatables I finally realized that rowKey is populated on row select, not on cell edit. rowIndex, however, is not null on cell edit, and reliably gives me the row number (zero-based) so I can retrieve the entire row's contents, and the values of the object used to populate the row (which in my case includes the value I wanted to put into rowKey) from Datatable.getValue(). The purpose of rowKey is not clear in the documentation (to me), so I thought I would share this for anyone encountering a similar problem.
The root cause has been explained by #snakedog already. I will add the code for remedying the issue.
Here is the attribute that you should put within p:datatable:
selectionMode="single"
If you do not want the selection highlight to be seen visually, add disabledSelection="true" as well.

How do I disable PrimeFaces column overflow hiding within a datatable

I'm currently working with a <p:dataTable> (from PrimeFaces 5.2) with many columns, and as I approach the width of the datatable's parent container, PrimeFaces starts hiding columns; unfortunately it seems to be the most important column (first on the left, a <p:datePicker>).
I've tried assigning that column a priority="1" and the other columns priority="3" as described on the ShowCase site, but the first column is still hidden.
In addition to just nesting the datatable within a <p:tabView> I've tried making the dataTable scrollable via scrollable="true" and assigning a width, or also try wrapping the datatable within a <p:scrollPanel> but the column was still being hidden in either case.
When I remove enough columns (from the right-most of the table), the hidden column will again reappear.
I'm interested in a solution that is not tied/hard-coded to a specific column, as I've run into this same issue on the 2nd column, or 3rd, depending on the resolution or browser width...I want to be sure that my users are seeing everything that was coded into the datatable, even if that means they have to scroll, rather than having a dynamic function suppress values unbeknownst to the user or myself.
Basically, I recommend to add tableStyle="width:auto" to a <p:datatable> so that you do not have to deal with the single columns width. Primefaces will handle it for you dynamically depending on the length of the column entry.

How to refresh data in p:dataTable, preserving filter and sorting?

How to refresh data in PrimeFaces DataTable preserving filtering and sorting options?
The DataTable is handling filtering internally, so after refresh data in backing bean the changes are yet not visible, it is necessary to invoke filter() on dataTable in JavaScript. At least in my case. Afterwards, the data are filtered, but they are not sorted! However, the styles on the column header are left, so the column is displayed as sorted, which is confusing to the end user (for him, it's a bug).
The dataTable has also a sort() function, but invoking it is causing an error:
TypeError: f is undefined
so it seems it's not the correct way of handling that case...
The official documentation is silent in that case, but the refresh button is the common case. Additionally the data should be auto-refreshed in my case, and the sorting and filtering shouldn't change.
So, how to re-sort the DataTable after data refresh? How to avoid writing the sort myself in backing bean and re-use PrimeFaces sorting?

How to use <h:selectOneRadio> on more than one datatable

I'm trying to achieve the well known feature of being able to select a datatable's row by using a radio button.
I have followed this blog:
http://balusc.blogspot.com/2006/06/using-datatables.html#SelectRowByRadioButton
It works perfectly if there is one datatable on the form, but when I add another one (even if it's placed on other form), and try to select a row there, the radio button gets selected then instantly unselected. The data is correctly set on the backing bean though.
Any ideas about how to extend the results of the above blog on more than one datatable?
Thank you
That script will group all radio buttons with the same component ID in the same form. So to fix your particular problem, put the other data table in a different form or give the other <h:selectOneRadio> a different ID.

Resources