Revision history [back]

click to hide/show revision 1
initial version

answered 2016-03-23 12:18:11 +0800

cor3000 gravatar image cor3000

ZK Team

another way is to use a ListSubModel

<zk>
    <chosenbox width="300px" noResultsText="no matches" 
               apply="zk.support.forum.ChosenBoxComposer"/>
</zk>

and create the model in your composer

package zk.support.forum;

import java.util.Comparator;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zkmax.zul.Chosenbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.ListModels;

public class ChosenBoxComposer extends SelectorComposer<Chosenbox> {

    @Override
    public void doAfterCompose(Chosenbox comp) throws Exception {
        super.doAfterCompose(comp);


        //Create a ListModelList containing/providing the available elements
        ListModelList<String> listModel = Stream.of(Locale.getAvailableLocales())
                .map(Locale::getDisplayName)
                .collect(Collectors.toCollection(ListModelList::new));

        //comparator to match the items
        Comparator<String> comparator = (search, localeName) -> 
                  localeName.toLowerCase().contains(search.toLowerCase()) ? 0 : 1;

        //wrap the model into a ListSubModel using the comparator, 
        //and a result limit of 10 elements
        ListModel<String> subModel = ListModels.toListSubModel(listModel, comparator, 10);

        comp.setModel(subModel);
    }
}

when typing up to 10 matching elements are shown in the available choices

another way is to use a ListSubModel

<zk>
    <chosenbox width="300px" noResultsText="no matches" 
               apply="zk.support.forum.ChosenBoxComposer"/>
</zk>

and create the model in your composer

package zk.support.forum;

import java.util.Comparator;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zkmax.zul.Chosenbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.ListModels;

public class ChosenBoxComposer extends SelectorComposer<Chosenbox> {

    @Override
    public void doAfterCompose(Chosenbox comp) throws Exception {
        super.doAfterCompose(comp);


        //Create a ListModelList containing/providing the available elements
        ListModelList<String> listModel = Stream.of(Locale.getAvailableLocales())
                .map(Locale::getDisplayName)
                .collect(Collectors.toCollection(ListModelList::new));

        //comparator to match the items
        Comparator<String> comparator = (search, localeName) -> 
                  localeName.toLowerCase().contains(search.toLowerCase()) ? 0 : 1;

        //wrap the model into a ListSubModel using the comparator, 
        //and a result limit of 10 elements
        ListModel<String> subModel = ListModels.toListSubModel(listModel, comparator, 10);

        comp.setModel(subModel);
    }
}

when typing up to 10 matching elements are shown in the available choiceschoices.

http://books.zkoss.org/wiki/ZKComponentReference/Input/Chosenbox#SubListModel

another way is to use a ListSubModel

<zk>
    <chosenbox width="300px" noResultsText="no matches" 
               apply="zk.support.forum.ChosenBoxComposer"/>
</zk>

and create the model in your composer

package zk.support.forum;

import java.util.Comparator;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zkmax.zul.Chosenbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.ListModels;

public class ChosenBoxComposer extends SelectorComposer<Chosenbox> {

    @Override
    public void doAfterCompose(Chosenbox comp) throws Exception {
        super.doAfterCompose(comp);
 
        //Create a ListModelList containing/providing the available elements
        ListModelList<String> listModel = Stream.of(Locale.getAvailableLocales())
                .map(Locale::getDisplayName)
                .collect(Collectors.toCollection(ListModelList::new));

        //comparator to match the items
        Comparator<String> comparator = (search, localeName) -> 
                  localeName.toLowerCase().contains(search.toLowerCase()) ? 0 : 1;

        //wrap the model into a ListSubModel using the comparator, 
        //and a result limit of 10 elements
        ListModel<String> subModel = ListModels.toListSubModel(listModel, comparator, 10);

        comp.setModel(subModel);
    }
}

when typing up to 10 matching elements are shown in the available choices.

http://books.zkoss.org/wiki/ZKComponentReference/Input/Chosenbox#SubListModel

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More