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+"')");
}
});
有人能告诉我为什么从不调用这些方法并给我写一些工作代码? 提前致谢, 彼得
答案 0 :(得分:1)
add(new AjaxEventBehavior(“onkeydown”)
需要“onkeydown”