Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force combobox to render autocomplete options?

Tags:

java

zk

This is my zul code:

<combobox id="digitalPublisherCombobox" value="@load(ivm.inventory.digitalPublisherName)"
        onOK="@command('setDigitalPublisher', digitalPublisherBox = self)" 
        onSelect="@command('setDigitalPublisher', digitalPublisherBox = self)"
        onChanging="@command('setupQuicksearchByEvent', searchlayout = event, prefix = 'PUB', tags = 'PublisherName, PublisherNameTranslit')"
        mold="rounded" hflex="1" buttonVisible="false" autodrop="true">
    <comboitem self="@{each=entry}" value="@{entry.key}" label="@{entry.value}"/>
</combobox>

And this is QuickSearch implementations:

@Command
public void setupQuicksearchByEvent(@BindingParam("searchlayout")Event event, @BindingParam("prefix") String prefix, @BindingParam("tags") String tags) throws WrongValueException, SearchException, IOException
{
    if(event instanceof InputEvent)
    {
        InputEvent inputEvent = (InputEvent) event;
        String inputText = inputEvent.getValue();

        List<String> searchFields = Arrays.asList(tags.split(","));
        ListModel model = new ListModelMap(ZKLogic.findDocsStartingWith(prefix, searchFields, "proxy", inputText), true);
        ListModel subModel = ListModels.toListSubModel(model, Autocompleter.MAP_VALUE_CONTAINS_COMPARATOR, 10);    
        Combobox searchBox = (Combobox) event.getTarget();
        searchBox.setModel(subModel); 

        searchBox.setItemRenderer(new ComboitemRenderer()
        {
            @Override
            public void render( Comboitem item, Object data, int pos ) throws Exception
            {
                String publisherString = data.toString();
                UID key = getUidFromPublisherString(publisherString);

                int startIndex = publisherString.indexOf('=') + 1;
                String publisher = publisherString.substring(startIndex);

                item.setLabel(publisher);
                item.setValue(key);
            }
        });
    }
}

ZKLogic.findDocsStartingWith return map with UID-key and String-value.

With code above I achieved to get dropdown list when I switch to another window. I need to type something, then select another browser or notepad window - and comboitems will be displayed immediately.

So, my question still need answer, is there are any techniques to reproduce this windows switching in code? Or maybe I should do something with autocomplete, because I've got some ac working with preloaded lists, but this thing should return only 10 records from db, instead of all 70000 entries, every time when user type something in the field.

Edit 20/09/2013: Problem still exist. Rename question a bit, because thing that I need is to call render option by force in code. Is there is any way to do it? Code hasn't changed a lot, but print option in render method said, that method can miss two or more onChange events and suddenly render text for one variant.

Maybe you know another autocomplete options in zk framework where database participating? I'm ready to change implementation, if there is a guide with working implementation of it.

like image 728
Dracontis Avatar asked Sep 06 '13 08:09

Dracontis


2 Answers

Ok I see two problems, you should solve first.

  1. Setting the Renderer in every call of setupQuicksearchByEvent(...).
    that is not logical, cos it is the same every time.
    Add to the zul combobox tag something like
     itemRenderer="@load(ivm.myRenderer)" .... 
  2. If you want just 10 items, do not let the db-request return more then 10.
    If you use JPA klick here or for sql here or just google a bit.

After you fixed this two issues, we can exclude these as a reason
of the unexpected behavior and fix it, if it is still present.

Edit

Ok, I have two possible ways to fix it.

  1. Call Combobox#invalidate()
    This schould force zk to rerender the Combobox, but could
    lead to low performance and I would not prefer this.

  2. Use Listbox with the select mold instead of Combobox.
    To force the rerender, use Listbox#renderAll()

like image 136
Nabil A. Avatar answered Oct 24 '22 19:10

Nabil A.


Try setting the selected item on your combobox or throw its related event

like image 22
Nikos Avatar answered Oct 24 '22 19:10

Nikos