primefaces: DataTable: manual assigning selection attr does not set internal selection state in DataTable component
Describe the defect If I use a DataTable with “multiViewState=true”, I can not set the selection using a Command Component like it is described within the Primefaces documentation (see here).
If I set the selection like that, the value in the data model is updated but not populated to the DataTableState. So when “DataTable.restoreMultiViewState()” is called afterwards the old selection is set, highlighted and overrides also the value within the data model.
This does not happen if the selection is set by clicking the target row because then the “SelectionFeature.decode(FacesContext context, DataTable table)” is called which updates the DataTableState too.
Reproducer This can be reproduced by creating the case like it is in the linked showcase (see description) but you need to set the “multiViewState” attribute to “true”, the “selectionMode” to “single” and the “disabledSelection” to “false”. It can be reproduced with prime faces 10 and 11.
This would look like that:
<p:dataTable var="car" value="#{carBean.cars}" selectionMode="single" multiViewState="true" disabledSelection="false"> <p:column> <p:commandButton value="Select"> <f:setPropertyActionListener value="#{car}" target="#{carBean.selectedCar}" /> </p:commandButton> </p:column> ...columns </p:dataTable>
Environment:
- PF Version: 11.0.1
- PF Theme: Diamond
- JSF + version: MyFaces 2.3.8
- Affected browsers: ALL
Expected behavior My expected behavior would be like that, it does not matter if I select the row by button or by clicking on the target row itself.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 30 (30 by maintainers)
Commits related to this issue
- test for #8406 — committed to primefaces/primefaces by tandraschko 2 years ago
- #8406 — committed to primefaces/primefaces by tandraschko 2 years ago
I made a simple example where the error can be reproduced. First select the second row (Entry_2) by clicking on the row itself, then switch the page with the paginator and then switch back. Now select Entry_3 by clicking the “Select” button. It does not work. This works fine if I set the “multiViewState” attribute to “false”. The example is based on your repo “https://github.com/primefaces/primefaces-test.git”. If I use your current master-SNAPSHOT then I got errors because of duplicate fragment names.
pf_test_1.zip