Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-2019

Chosenbox work incorrectly when using ListSubModel and Comparator

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 6.5.5, 7.0.1
    • 6.5.3, 6.5.4
    • Components
    • None
    • and Version 7.0.0-RC

      As declaredat http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zul/ListModels.html#toListSubModel(org.zkoss.zul.ListModel, java.util.Comparator, int),
      comparator - used to compare the value typed by user and the value from the model. The first argument is the value typed by user, and the second argument is the value retrieved from the model. It shall return 0 if they matched (i.e., shall be shown).

      I tried to filter the model data with "full text matching",and the logs show that CustomerSortComparator works correctly,
      But, the chosenbox drop down with empty list.

      But if the input value matches the data at the beginning,it will appear in the chosenbox drop down list,
      just like the CustomerSortComparator was invoked and ignored!

      ListModels.toListSubModel(new ListModelList<String>(dataList, false),new CustomerSortComparator(), 100);

      CustomerSortComparator.java
      public class CustomerSortComparator implements Comparator<String> {
      		@Override
      		public int compare(String paramT1, String paramT2) {
      			if (StringUtils.isEmpty(paramT1)) {
      				logger.debug("empty not matching " + paramT2);
      				return -1;
      			}
      			boolean matching = paramT2.indexOf(paramT1) >= 0;
      			if (matching) {
      				logger.debug("compare[" + paramT1 + "|" + paramT2 + "]matching");
      				return 0;
      			} else {
      				return -1;
      			}
      		}
      
      	}
      

            RaymondChao RaymondChao
            daquan198163 daquan198163
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: