You should not use an AjaxFormComponentUpdatingBehavior if you want to capture keys. This behavior is reserved for actions that update the form component model. I would probably try to do it in javascript alone, especially if you are using a javascript framework like mootools or prototype. Here is some sample code for mootools (no need to send this to the server):
this.add(new TextField<String>("textField").add(new AbstractBehavior(){
private static final long serialVersionUID = 1L;
private Component component;
@Override
public void bind(final Component component){
this.component = component.setOutputMarkupId(true);
}
@Override
public void renderHead(final IHeaderResponse response){
response.renderOnDomReadyJavascript(
"$('" + this.component.getMarkupId() + "')" +
".addEvent('keyup',function(event){" +
"if(' '==event.key){" +
"alert('you pressed space!!!')" +
"}" +
"}" +
");");
};
}));
if no js library is available, here's a wicket-only solution:
@Override
public void renderHead(final IHeaderResponse response){
response.renderJavascriptReference(WicketEventReference.INSTANCE);
response.renderOnDomReadyJavascript("Wicket.Event.add('"
+ this.component.getMarkupId()
+ "',onkeyup',function(event){" + "if(' '==event.key){"
+ "alert('you pressed space!!!')" + "}" + "}" + ");");
};
but this does not deal with cross-browser issues in event handling