Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datatable: Row remains selected after clearing backing bean #7391

Closed
doteo78 opened this issue Jun 7, 2021 · 12 comments · Fixed by #7403
Closed

Datatable: Row remains selected after clearing backing bean #7391

doteo78 opened this issue Jun 7, 2021 · 12 comments · Fixed by #7403
Assignees
Labels
10.0.6 🐞 defect Bug...Something isn't working
Milestone

Comments

@doteo78
Copy link

doteo78 commented Jun 7, 2021

Describe the defect
Basic datatable with single selection: when a row is selected and an action that clears the backing bean selected row object is executed, the row remains selected in the browser.

This only happens when the datatable has declared the "rowSelect" event.

Reproducer
Run the attached project (mvn jetty:run) and visit http://localhost:8080/primefaces-test/. Then select a row and click "Unselect row" button. The row remains selected in the browser.

It works fine (the row is no longer selected) if you comment out the following line in test.xhtml:

<p:ajax event="rowSelect" listener="#{testView.onSelectProduct}" />

Environment:

  • PF Version: 10.0.x
  • JSF + version: Mojarra 2.2.20 and MyFaces 2.3.9
  • Affected browsers: ALL

primefaces-test-master.zip

@doteo78 doteo78 added the 🐞 defect Bug...Something isn't working label Jun 7, 2021
@tandraschko
Copy link
Member

@melloware @christophs78 do we have a integration test for this?

@melloware
Copy link
Member

We have tons of selection tests. Let me add this specific case and see.

@tandraschko
Copy link
Member

integration moved to this repo now, feel free to work on it :)

@melloware
Copy link
Member

Failing Integration Test provided.

@melloware
Copy link
Member

here is a workaround for now. Give your Datatable a widgetVar like widgetVar="selectTable" and then add this to your command button.

<p:commandButton 
   process="@this" 
   update="@form"
   value="Unselect row" 
   action="#{testView.unselectRow}" 
   onclick="PF('selectTable').clearSelections();"
   oncomplete="PF('selectTable').unselectAllRows();" />

@melloware melloware added the workaround A workaround has been provided label Jun 10, 2021
@tandraschko
Copy link
Member

Did this work in 8.0?

@melloware
Copy link
Member

Looks like it did in 8.0 the selection is cleared. Attached is 8.0 reproducer.
pf-7391-80.zip

@doteo78
Copy link
Author

doteo78 commented Jun 10, 2021

here is a workaround for now. Give your Datatable a widgetVar like widgetVar="selectTable" and then add this to your command button.

<p:commandButton 
   process="@this" 
   update="@form"
   value="Unselect row" 
   action="#{testView.unselectRow}" 
   onclick="PF('selectTable').clearSelections();"
   oncomplete="PF('selectTable').unselectAllRows();" />

That's what I'm doing for now. Indeed I am checking if there were validation errors because I don't want to unselect the row if the action (business logic) could not be done. For example:

oncomplete="if(!args.validationFailed) {PF('$dtCategories').unselectAllRows()}"

@melloware
Copy link
Member

When I debug 8.0 vs 10.0 in the Javascript for setupSelection the _selection value holder has the value in 10.0 and does not in 8.0.

setupSelection: function() {
        this.selectionHolder = this.jqId + '_selection';
        this.cfg.rowSelectMode = this.cfg.rowSelectMode||'new';
        this.rowSelector = '> tr.ui-widget-content.ui-datatable-selectable';
        this.cfg.disabledTextSelection = this.cfg.disabledTextSelection === false ? false : true;
        this.cfg.selectionPageOnly = this.cfg.selectionPageOnly === false ? !this.cfg.paginator : true;
        this.rowSelectorForRowClick = this.cfg.rowSelector||'td:not(.ui-column-unselectable):not(.ui-grouped-column),span:not(.ui-c)';

        var preselection = $(this.selectionHolder).val();

Investigating more.

@melloware
Copy link
Member

I think its the SelectionFetaure does a decode but there is never anything on the encode that checks and re-valuates the selection and sets the selectedRowKeys value based on the user setting.

melloware added a commit to melloware/primefaces that referenced this issue Jun 10, 2021
@melloware melloware self-assigned this Jun 10, 2021
@melloware melloware added this to the 11.0.0 milestone Jun 10, 2021
@melloware melloware linked a pull request Jun 10, 2021 that will close this issue
@melloware
Copy link
Member

Figured it out. Thanks for the reproducer helping me debug it!

@buunsal buunsal added elite This issue is related to an Elite release 10.0.6 and removed elite This issue is related to an Elite release workaround A workaround has been provided labels Aug 17, 2021
@doteo78
Copy link
Author

doteo78 commented Aug 19, 2021

Working properly with version 10.0.6. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10.0.6 🐞 defect Bug...Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants