Search code examples
javaapachewickettextfieldonupdate

Update Wicket Text Field on onUpdate event


I have a component that extends TextField where a user can type an web address. I want that after the user type something (for example www.example.org) to change that value to something else (for exemple http://www.example.org)

I have tried this:

urlField = new TextFieldIndicatingError<String>("url", new PropertyModel<String>(this, "url"));
urlField.add(new AjaxFormComponentUpdatingBehavior("onblur") {
                     @Override
                     protected void onUpdate(AjaxRequestTarget target) 
                     {
                         //url = "ABCDDEE";
                         urlField.getModel().setObject("AAAA");
                     }
                 });

but anything inside the onUpdate() doesn't seems to have an effect in the TextField's value. What I'm doing wrong here?


Solution

  • You need to use target.add(urlField) to update it on the client side after setting its new model.