6

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.

Dracontis
  • 4,184
  • 8
  • 35
  • 50
  • So your problem is, that `setupQuicksearchByEvent(...)` is not invoked for every `onChanging` but if it is, then the dropdown refreshes. Right? Or is the problem just, that it do not render every time? – Nabil A. Sep 25 '13 at 07:47
  • The problem is that setupQuicksearchByEvent invoked all the time, but results aren't rendered. I should press tab, then return to control and continue entering characters to get dropdown. I know that autocomplete works good with predefined lists, but I can't store 60k records in a list. – Dracontis Sep 27 '13 at 06:35

3 Answers3

3

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()

Community
  • 1
  • 1
Nabil A.
  • 3,270
  • 17
  • 29
  • It still present. It wasn't because of renderer, as problem existed before I implemented it. And method 'findDocsStartingWith' returns 10 records from database for sure. – Dracontis Sep 27 '13 at 06:24
  • Ok, I got you wrong. So I made two suggestions to fix your problem. – Nabil A. Sep 28 '13 at 19:38
  • I tried invalidate - it won't work. I really hope to avoid listbox, as it well known fix, but then it's only way. – Dracontis Sep 28 '13 at 21:58
1

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

Nikos
  • 7,295
  • 7
  • 52
  • 88
0

Solution is simple. Really. Nothing is better then brute-force, but I think I tried to avoid it and use it in despair.

 @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(","));
        Map<UID, String> publishers = ZKLogic.findDocsStartingWith(prefix, searchFields, "proxy", inputText);

        Combobox searchBox = (Combobox) event.getTarget();
        searchBox.getChildren().clear();

        for (Map.Entry<UID, String > entry : publishers.entrySet())
        {
            Comboitem item = new Comboitem();
            item.setLabel(entry.getValue());
            item.setValue(entry.getKey());
            searchBox.appendChild(item);
        }
    }
}
Dracontis
  • 4,184
  • 8
  • 35
  • 50