Details
-
Improvement
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
selections-5.6.1
-
Flagged
-
Unlimited Support (Non-Billable)
Description
Dynamic dropdown is currently unable to resort its values.
Reproduction path:
suppose you have two dropdows: 1. dropdown to select countries and 2. dropdown to select cities in that country.
- first dropdown is statically connected to countries value list, and has a listener to listen for any chnanges
- second dropdown uses this listener to dynamically change location of cities value list.
- resorting does not happen.
DynamicDropdownPlugin does sorting for the first time when frontend component is being created in constructor. There is nothing to sort though in the beginning.
org.onehippo.forge.selection.frontend.plugin.sorting.SortHelper has following code:
public void sort(ValueList valueList, IPluginConfig config) { if (valueList == null) { return; } final String comparatorClass = config.getString(Config.SORT_COMPARATOR); if (comparatorClass != null) { // instantiate only once if (listItemComparator == null) { if (comparatorClass.equals(DEFAULT_COMPARATOR_CLASS)) { listItemComparator = new DefaultListItemComparator(); } else { // load class dynamically and instantiate try { Class clazz = Class.forName(comparatorClass); Object instance = clazz.newInstance(); if (instance instanceof IListItemComparator) { listItemComparator = (IListItemComparator) instance; } else { log.error("Configured class " + comparatorClass + " does not implement IListItemComparator, using NO comparator"); } } catch (ClassNotFoundException e) { log.error("ClassNotFoundException for configured class " + comparatorClass + ", using NO comparator"); } catch (InstantiationException e) { log.error("InstantiationException for configured class " + comparatorClass + ", using NO comparator"); } catch (IllegalAccessException e) { log.error("IllegalAccessException for configured class " + comparatorClass + ", using NO comparator"); } } if (listItemComparator != null) { listItemComparator.setConfig(config); Collections.sort(valueList, listItemComparator); } } } }
The problem is that "listItemComparator" only sorts when it is created and not anymore afterwards. When listener of countries dropdown "notices" change, and cities dropdown needs to be redrawn, listItemComparator of cities dropdown is already initialized, and nothing happens. To fix it please allow sorting for already initialized listItemComparator.