在处理向检票口AutoCompleteTextField的onchange事件 [英] handling to onchange event of AutoCompleteTextField in wicket
问题描述
我在写一个自动完成组件使用Java和Wicket web应用程序。
I'm writing an autocomplete component for a webapp using Java and Wicket.
有没有办法来处理onchange事件,当用户选择的自动完成列表中的一个选项来运行一些code?我试图在AutoCompleteTextField这样做的:
Is there a way to handle the onchange event to run some code when the user selects one of the options of the autocomplete list? I tried doing this in the AutoCompleteTextField:
setOutputMarkupId(true);
add(new AjaxEventBehavior("onchange") {
@Override
protected void onEvent(AjaxRequestTarget target) {
System.out.println(getInput());
}
});
但getInput方法返回null。 :(结果
有没有办法来反应onchange事件,并能够读取用户输入什么?
But the getInput method returns null. :(
Is there a way to react to the onchange event and to be able to read what the user has entered?
感谢您的时间和知识:)
Thanks for you time and knowledge :)
推荐答案
<击>当焦点移动从元件远的onchange
事件只被解雇。 (这是一个普遍的浏览器/ JavaScript的东西。)
The onchange
event is only fired when the focus is moved away from the component. (This is a universal browser/javascript thing.)
您需要连接你的处理器到安其preSS
事件来代替。击>
You need to hook your handler to the onkeypress
event instead.
您需要的不是 AjaxEventBehavior
,但 AjaxFormComponentUpdatingBehavior
:
add( new AjaxFormComponentUpdatingBehavior( "onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println( "Value: "+field.getValue() );
}
});
虽然与工作getInput()
太,但通常略高的水平(正常逃脱,由模型支持)的getValue()
是更好的选择。
Although it works with getInput()
too, but usually the somewhat higher level (properly escaped and backed by the model) getValue()
is a better fit.
这篇关于在处理向检票口AutoCompleteTextField的onchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!