2
votes

I have a text field for user input and as soon as it gets a content, I want to perform a service call.

I have added the OnChangeAjaxBehavior onUpdate() method for that, but it indicates the service call after every character.

My code:

getTextField().add(new OnChangeAjaxBehavior() {
                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    protected void onUpdate(AjaxRequestTarget target) {
                                        refreshDependingComponents(target);
                                        TemplatePage.refreshFeedback(target, getTextField());
                                        getModelObject().setPeriod(getTextField().getInput());
                                        if (code!= null) {
                                            target.add(code);
                                        }
                                    }

How can I do that it only make the update and refresh when the user has already clicked away from the textfield?

Thank you!

1

1 Answers

4
votes

For TextField and TextArea form components OnChangeAjaxBehavior uses both input and change JavaScript events, and this is the reason why it fires Ajax calls for each letter.

You can use new AjaxFormComponentUpdatingBehavior("change") instead. It will fire Ajax call only on change event.