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

SelectCheckboxMenu: Order of selected items not kept #8119

Closed
RedRobin84 opened this issue Nov 27, 2021 · 7 comments · Fixed by #11185
Closed

SelectCheckboxMenu: Order of selected items not kept #8119

RedRobin84 opened this issue Nov 27, 2021 · 7 comments · Fixed by #11185
Assignees
Labels
enhancement Additional functionality to current component
Milestone

Comments

@RedRobin84
Copy link

Greetings,

When using selectCheckboxMenu component (with attribute multiple="true"), after each item selection, the order of selected items in Collection resets exactly to order of the items in collection, thats used as available items to choose (in this case f:selectItems component)

E.g. use collection List 1,2,3,4, users chooses items in this order 4,3,2, but the result is stored as 2,3,4. I am situation, where I need exactly the order of items that was chosen by the user. Now I need to use workaround with ajax request event="change" and manually sort those elements in viewBean.

Could this be a new feature (new attribute keepOrder or something? Or is it a bug?

Thanks!

image

Environment

  • PF Version: 8.0
  • JSF + version: e.g. Mojarra 2.2.20 or MyFaces 2.3.9
  • Affected browsers: e.g. Chrome, iOS, ALL

To Reproduce
Steps to reproduce the behavior:

  1. User component selectCheckboxMenu
  2. add atribute multiple="true"
  3. Select few items and see its stored in different order than displayed

Expected behavior
Sequence of the elements user choose should be stored in order, thats displayed on screen.

@RedRobin84 RedRobin84 added the 🐞 defect Bug...Something isn't working label Nov 27, 2021
@tandraschko tandraschko added enhancement Additional functionality to current component and removed 🐞 defect Bug...Something isn't working labels Nov 27, 2021
@melloware melloware changed the title selectCheckboxMenu: Order of selected items not kept SelectCheckboxMenu: Order of selected items not kept Nov 28, 2021
@melloware melloware self-assigned this Apr 26, 2022
@melloware
Copy link
Member

Please provide an executable example using the PrimeFaces Test project.

It will help me debug the issue

@melloware
Copy link
Member

Reproducer:
pf-8119.zip

The values are just submitted in the form in the order they are in the DOM currently.

@melloware melloware removed their assignment Apr 28, 2022
@melloware
Copy link
Member

cc @ltlBeBoy not sure if you want to look at this one too.

@ltlBeBoy
Copy link
Contributor

@melloware Yes, I will take a look at.

@ltlBeBoy
Copy link
Contributor

ltlBeBoy commented Jan 19, 2023

Maybe a hidden input with the selection order would do the job.
Because internally hidden checkboxes are used to submit the selected values. And the order of these checkboxes is according to the select item list.

@melloware
Copy link
Member

melloware commented Jan 19, 2023

Yep we need some sort of JS Array holding the order they were pushed into the list and then submit that array order to the backing bean.

@melloware
Copy link
Member

OK changing the core component was too much of a nightmare and not worth it. So I added itemSelect event so now you can do this...

<p:ajax event="itemSelect" listener="#{checkboxView.onItemSelect}"/>
<p:ajax event="itemUnselect" listener="#{checkboxView.onItemUnselect}"/>

So now that you have an itemSelect and unselect you can track the order the items were clicked using AJAX.

    public void onItemSelect(SelectEvent event) {
        FacesMessage msg = new FacesMessage();
        msg.setSummary("Item selected: " + event.getObject().toString());
        msg.setSeverity(FacesMessage.SEVERITY_INFO);

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public void onItemUnselect(UnselectEvent event) {
        FacesMessage msg = new FacesMessage();
        msg.setSummary("Item unselected: " + event.getObject().toString());
        msg.setSeverity(FacesMessage.SEVERITY_INFO);

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additional functionality to current component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants