AjaxFormComponentUpdatingBehavior onkeypress

时间:2015-05-06 07:03:51

标签: java ajax web wicket

我有一个项目列表,上面有一个输入字段 输入字段是一个过滤器,它应该根据您输入到输入字段的文本过滤列表。

例如: 如果您输入" th",它应该过滤列表,以便所有项目都应以" th"开始。

为此我使用AjaxFormComponentUpadingBehavior(" onkeypress")。
但这似乎并没有按照应有的方式发挥作用 当我键入某些东西时,它会清除它并将光标移动到输入字段的第一个字母。

我试过onkeyup和onkeydown,所有这些都是以同样的方式行事 现在我正在对链接点击进行过滤,但我希望它与onkeypress一样无缝。

有没有办法实现这个目标? 我正在使用wicket 1.4.x

以下是代码:

        // 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);

1 个答案:

答案 0 :(得分:1)

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

相关问题