[MAGNOLIA-4511] MultiSelect does not keep the order of its value items (NodeDatas) Created: 13/Aug/12  Updated: 28/Nov/12  Resolved: 26/Sep/12

Status: Closed
Project: Magnolia
Component/s: admininterface
Affects Version/s: 4.4.6
Fix Version/s: 4.5.5

Type: Bug Priority: Neutral
Reporter: Will Scheidegger Assignee: Jaroslav Simak
Resolution: Fixed Votes: 0
Labels: multiselect, nodedatacollection, order, sort
Remaining Estimate: 1h
Time Spent: Not Specified
Original Estimate: 1h

Attachments: PNG File Screen Shot 2012-08-27 at 12.16.34.png     PNG File Screen Shot 2012-08-27 at 12.16.49.png     PNG File Screen Shot 2012-08-27 at 12.17.02.png     Text File multiSelect.patch    
Issue Links:
Cloners
is cloned by MAGNOLIA-4692 CLONE -MultiSelect does not keep the ... Closed
is cloned by MAGNOLIA-4692 CLONE -MultiSelect does not keep the ... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

If you use the multiSelect control in a dialog to select three nodes A, B and C, Magnolia will correctly save something like

  • myMultiValueNode
    • 0: A
    • 1: B
    • 2: C

But when you open the dialog the next time, chances are that the order will not be correct anymore. You save again and the order will now also be messed up in the repository. I don't know exactly why this is happening, but it boils down to Content.getNodeDataCollection() not returning the nodes in the "proper" order.

However this is easily fixed: Simply sort the NodeDatas by name when retrieved from the Content object:

ArrayList<NodeData> nodeDatas = new ArrayList<NodeData>(this.getStorageNode().getContent(this.getName()).getNodeDataCollection());

Collections.sort(nodeDatas, new Comparator() {
@Override
public int compare(Object arg0, Object arg1)

{ return ((NodeData) arg0).getName().compareTo(((NodeData) arg1).getName()); }

});
Iterator it = nodeDatas.iterator();
...

The attached patch does exactly this.



 Comments   
Comment by Ondrej Chytil [ 23/Aug/12 ]

Hi Will,

except messing up directly with stored values I'm unable to reproduce the issue (by just inserting/saving/re-opening dialog). Even after several attempts order is fine (which seems to eliminate random effect for me).
Are you able to reproduce this on fresh instance?

Comment by Will Scheidegger [ 27/Aug/12 ]

You can even reproduce this on the demo version with Mag 4.5:

  • Screenshot 1 shows the categories selected before saving
  • Screenshot 2 shows the categories after saving
  • Screenshot 3 shows the multiselect control that I have added to the Contact dialog.
Comment by Ondrej Chytil [ 27/Aug/12 ]

That helped, thanks Will. Added for current changelog.

Comment by Jan Haderka [ 26/Sep/12 ]

Could you please use GIVEN/WHEN/THEN pattern for the tests? Thx.

Generated at Mon Feb 12 03:56:29 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.