Events 永远不会调用updateAjaxAttributes
在stackoverflow上,我为Wicket找到了一些代码,这些代码应该响应用户在页面上的按键操作;我只是做了一些小小的修改。问题在于,当用户按下页面上的某些键时,updateAjaxAttributes方法和OneEvent方法永远不会被调用。代码如下:Events 永远不会调用updateAjaxAttributes,events,wicket,listener,keydown,Events,Wicket,Listener,Keydown,在stackoverflow上,我为Wicket找到了一些代码,这些代码应该响应用户在页面上的按键操作;我只是做了一些小小的修改。问题在于,当用户按下页面上的某些键时,updateAjaxAttributes方法和OneEvent方法永远不会被调用。代码如下: add(new AjaxEventBehavior("keydown") { @Override protected void updateAjaxAttributes(AjaxReques
add(new AjaxEventBehavior("keydown")
{
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
IAjaxCallListener listener = new AjaxCallListener(){
@Override
public CharSequence getPrecondition(Component component) {
//this javascript code evaluates wether an ajaxcall is necessary.
//Here only by keyocdes for TAB and ENTER
return "var keycode = Wicket.Event.keyCode(attrs.event);" +
"if ((keycode == 9) || (keycode == 13))" +
" return true;" +
"else" +
" return false;";
}
};
attributes.getAjaxCallListeners().add(listener);
//Append the pressed keycode to the ajaxrequest
attributes.getDynamicExtraParameters()
.add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" +
"return {keycode: eventKeycode};");
//whithout setting, no keyboard events will reach any inputfield
attributes.setAllowDefault(true);
}
@Override
protected void onEvent(AjaxRequestTarget target) {
//Extract the keycode parameter from RequestCycle
final Request request = RequestCycle.get().getRequest();
final String jsKeycode = request.getRequestParameters()
.getParameterValue("keycode").toString("");
target.appendJavaScript("alert('from wicket ajax. you pressed "+jsKeycode+"')");
}
});
有人能告诉我为什么这些方法从未被调用,并给我写一些工作代码吗?
提前感谢,,
Pietro添加(新的AjaxEventBehavior(“onkeydown”)
“onkeydown”是必需的看起来不错,您如何知道该方法没有被调用?