Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何强制combobox呈现自动完成选项?_Java_Zk - Fatal编程技术网

Java 如何强制combobox呈现自动完成选项?

Java 如何强制combobox呈现自动完成选项?,java,zk,Java,Zk,这是我的zul代码: <combobox id="digitalPublisherCombobox" value="@load(ivm.inventory.digitalPublisherName)" onOK="@command('setDigitalPublisher', digitalPublisherBox = self)" onSelect="@command('setDigitalPublisher', digitalPublisherBox

这是我的zul代码:

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

这是QuickSearch实现:

@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);
            }
        });
    }
}
@命令
public void setupQuicksearchByEvent(@BindingParam(“searchlayout”)事件、@BindingParam(“prefix”)字符串前缀、@BindingParam(“tags”)字符串标记)引发错误的ValueException、SearchException、IOException
{
if(InputEvent的事件实例)
{
InputEvent InputEvent=(InputEvent)事件;
字符串inputText=inputEvent.getValue();
List searchFields=Arrays.asList(tags.split(“,”);
ListModel model=newlistmodelmap(ZKLogic.finddocstartingwith(前缀,搜索字段,“代理”,inputText),true);
ListModel子模型=ListModels.toListSubModel(模型,Autocompleter.MAP\u值\u包含\u比较器,10);
Combobox searchBox=(Combobox)事件。getTarget();
searchBox.setModel(子模型);
setItemRenderer(新的ComboitemRenderer())
{
@凌驾
公共void呈现(Comboitem、对象数据、int-pos)引发异常
{
字符串publisherString=data.toString();
UID键=getUidFromPublisherString(publisherString);
intstartindex=publisherString.indexOf('=')+1;
String publisher=publisherString.substring(startIndex);
item.setLabel(发布者);
项。设置值(键);
}
});
}
}
ZKLogic.finddocstartingwith
返回带有UID键和字符串值的映射

通过上面的代码,我可以在切换到另一个窗口时获得下拉列表。我需要键入一些内容,然后选择另一个浏览器或记事本窗口,然后将立即显示comboitems

所以,我的问题仍然需要回答,是否有任何技术可以复制这个窗口切换代码?或者我应该用autocomplete做点什么,因为我有一些ac在处理预加载的列表,但是每次用户在字段中键入内容时,这个东西应该只从db返回10条记录,而不是所有70000条记录

《编辑》20130920:问题依然存在。稍微重命名一下这个问题,因为我需要的是在代码中强制调用render选项。有什么办法吗?代码并没有太大变化,但render方法中的print选项表示,该方法可能会错过两个或多个onChange事件,并突然为一个变体呈现文本


也许您知道zk框架中的另一个自动完成选项,其中有数据库参与?我准备更改实现,如果有关于它的工作实现的指南。

尝试在组合框上设置所选项目或抛出其相关事件。

好的,我看到两个问题,您应该首先解决

  • 在每次调用
    setupQuicksearchByEvent(…)
    时设置渲染器
    这不符合逻辑,因为每次都是一样的。
    添加到zul组合框标记中,如
     itemRenderer="@load(ivm.myRenderer)" ....
    
    itemRenderer=“@load(ivm.myRenderer)”
  • 如果只需要10项,请勿让db请求返回超过10项。
    如果您使用JPA klick或for sql,或者只使用谷歌一点。
  • 在您解决了这两个问题后,我们可以排除这些问题,将其作为意外行为的原因
    ,并修复它(如果它仍然存在)

    编辑 好的,我有两种可能的解决方法

  • 调用组合框#invalidate()
    这将迫使zk重新启动
    组合框
    ,但可能
    导致性能低下,我不希望这样

  • 将列表框与选择模具一起使用,而不是组合框
    要强制重新加载,请使用


  • 解决办法很简单。真正地没有什么比暴力更好了,但我想我试图避免它,并在绝望中使用它

     @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);
            }
        }
    }
    
    @命令
    public void setupQuicksearchByEvent(@BindingParam(“searchlayout”)事件、@BindingParam(“prefix”)字符串前缀、@BindingParam(“tags”)字符串标记)引发错误的ValueException、SearchException、IOException
    {
    if(InputEvent的事件实例)
    {
    InputEvent InputEvent=(InputEvent)事件;
    字符串inputText=inputEvent.getValue();
    List searchFields=Arrays.asList(tags.split(“,”);
    Map publishers=ZKLogic.finddocStartingWith(前缀,搜索字段,“代理”,inputText);
    Combobox searchBox=(Combobox)事件。getTarget();
    searchBox.getChildren().clear();
    对于(Map.Entry:publisher.entrySet())
    {
    Comboitem=新Comboitem();
    item.setLabel(entry.getValue());
    item.setValue(entry.getKey());
    searchBox.appendChild(项目);
    }
    }
    }
    
    尝试将onRender事件发送到combobox,但仍然没有发生任何事情。因此,您的问题是,
    setupQuicksearchByEvent(…)
    不会对每次
    更改调用,但如果是,则下拉列表会刷新。对吗?或者问题只是,它不是每次都呈现?问题是setupQuicksearchByEvent一直在调用,但结果没有呈现。我应该按tab键,然后返回控件并继续输入字符以获得下拉列表。我知道autocomplete可以很好地处理预定义的列表,但我无法在列表中存储60k条记录。它仍然存在。这不是因为渲染器,因为在我实现它之前就存在这个问题。方法“FindDocStartingWith”肯定会从数据库返回10条记录。好吧,我搞错了。因此,我提出了两个建议来解决您的问题。我尝试了无效-它不会起作用。我真的希望避免listbox,因为它是众所周知的修复方法,但这是唯一的方法。