Uploaded image for project: '[Read Only] - Hippo Plugins'
  1. [Read Only] - Hippo Plugins
  2. HIPPLUG-1579

In selections plugin dynamic dropdown does not know to sort values

    XMLWordPrintable

Details

    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.

      1. first dropdown is statically connected to countries value list, and has a listener to listen for any chnanges
      2. second dropdown uses this listener to dynamically change location of cities value list. 
      3. 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.

      Attachments

        Activity

          People

            imurasko Ilja Murasko (Inactive)
            imurasko Ilja Murasko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: