首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AjaxFormComponentUpdatingBehavior onkeypress

AjaxFormComponentUpdatingBehavior onkeypress
EN

Stack Overflow用户
提问于 2015-05-06 07:03:50
回答 1查看 735关注 0票数 0

我有一个项目列表,上面有一个输入字段。

输入字段是一个过滤器,它应该根据输入字段输入的文本过滤列表。

例如:如果键入"th",它应该筛选列表,以便所有项目都以"th“开头。

为此,我使用AjaxFormComponentUpadingBehavior("onkeypress").

但这似乎是行不通的--他们应该这样做。

当我输入某项内容时,它会清除它,并将光标移到输入字段的第一个字母。

我试过onkeyup和onkeydown,它们的行为都是一样的。

现在,我正在做一个链接点击过滤器的工作,但我希望它是无缝的按钮。

有办法做到这一点吗?我使用的是wicket 1.4.x

以下是代码:

代码语言:javascript
复制
        // Customer Filter input field
        customerFilterTxt = new TextField<String>("customerFilterTxt", new PropertyModel<String>(this, "slectedCustomerFilterStr"));
        customerFilterTxt.setOutputMarkupPlaceholderTag(true);
        customerListViewContainer.add(customerFilterTxt);

        // Ajax behavior for customer group filter auto complete input filed
        AjaxFormComponentUpdatingBehavior customerGroupFilterBehave = new AjaxFormComponentUpdatingBehavior("onkeypress") {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                List<CustomerGroupBean> filterList = new ArrayList<CustomerGroupBean>();
                if(Util.hasValue(selectedCustomerGroupFilterStr)) {
                    String str = selectedCustomerGroupFilterStr.toUpperCase();

                    for(CustomerGroupBean group : custGroupList) {
                        if(group.getRightGroupName().toUpperCase().contains(str)) {
                            filterList.add(group);
                        }
                    }

                    custGroupListView.setList(filterList);

                } else {
                    custGroupListView.setList(custGroupList);
                }

                target.addComponent(customerFilterTxt);
                target.addComponent(custGroupListViewContainer);
            }
        };
        customerGroupFilterTxt.add(customerGroupFilterBehave);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-06 07:33:35

在update方法中将输入字段添加到更新调用中。这指示Wicket替换输入字段,再次呈现文本字段。这就是为什么光标跳到第一个位置的原因。为什么要将文本字段添加到更新中?我看不出有什么必要。此外,您可能希望使用事件"onkeyup"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30069734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档