java AjaxFormComponentUpdateingBehavior onkeypress
我有一个项目列表,上面有一个输入字段
输入字段是一个过滤器,它应该根据输入字段的文本过滤列表
例如: 如果您键入“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 楼答案
将输入字段添加到update方法中的update调用中。这将指示Wicket替换输入字段,再次呈现文本字段。这就是光标跳到第一个位置的原因。为什么要将文本字段添加到更新中?我看没有必要这么做。此外,您可能还想使用事件
"onkeyup"