I am developing a Primefaces 6.2 application in which I use the datatable component in edit mode.
<p:remoteCommand name="refrescarTabla"
actionListener="#{bean.dlgEditar.refrescarTabla}"
update="pgTabla"/>
<h:panelGroup id="pgTabla">
<p:dataTable id="tabla" var="reg"
value="#{bean.dlgEditar.datos}" editable="true" editMode="cell"
widgetVar="cellDato">
<p:ajax event="cellEdit"
listener="#{bean.dlgEditar.alEditarRegistro}"
oncomplete="refrescarTabla()"/>
...
</p:datatable>
</h:panelGroup>
When I first edit a table cell, the component works correctly.
There are columns that depend on others, so when I make a change in a cell, I have to refresh the table (for this I use the remoteCommand component) to reflect the changes. From this moment the problem appears, and it is that if I try to edit a cell again, said cell loses focus in a matter of less than a second, so I cannot edit the value.
I have seen some recommendations like this post from BalusC on SO: https://stackoverflow.com/a/19927578/2131029 , however I have not been able to solve the problem.
EDITION 1
I just created an example that reproduces the problem: https://github.com/hecnabae/pf-datatable .
The example shows the ingredients of a recipe in table form. The fields it displays are name, amount, and percentage. When editing a field (amount is editable), the remotecommand is launched to update the table.
To reproduce the problem, we simply try to edit the quantity of one ingredient, and then click on the quantity of another ingredient (to edit it as well). We will see the effect of instant loss of focus.
The problem originates from the following sequence of events:
cellEdit
p:remoteCommand
Result?
The html view of the table and the internal state of the table
p:dataTable
disagree. The html view is rendered as no active edition, but the internal state of the dataTable shows that there is an active edition.What happens is a logical consequence when performing the complete update, primefaces does not support that when editing a cell the entire table is updated.
possible solutions
A hack solution would be to modify the internal state of the
p:dataTable
once the onep:remoteCommand
that updates it is completed, in the following way:Another option would be not to use cell editing, but rather full row editing. This makes it more difficult to quickly edit different rows while reloading the entire table.