Handling AutoCompleteTextField onchange event in wickets

I am writing an autocomplete component for webapp using Java and Wicket.

Is there a way to handle the onchange event to run some code when the user selects one of the options for the autocomplete list? I tried to do this in AutoCompleteTextField:

setOutputMarkupId(true); add(new AjaxEventBehavior("onchange") { @Override protected void onEvent(AjaxRequestTarget target) { System.out.println(getInput()); } }); 

But the getInput method returns null. :(
Is there a way to respond to the onchange event and find out what the user entered?

Thank you for your time and knowledge :)

+7
source share
1 answer

The onchange event is onchange only when focus is removed from the component. (This is the universal version of browser / javascript.)

Instead, you need to bind the handler to the onkeypress event.

You need not AjaxEventBehavior , but AjaxFormComponentUpdatingBehavior :

  add( new AjaxFormComponentUpdatingBehavior( "onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { System.out.println( "Value: "+field.getValue() ); } }); 

Although it works with getInput() well, usually a slightly higher level (properly shielded and supported by the model) getValue() better suited.

+7
source

All Articles