Question

final Address address = new Addres();
Form form = new Form("addressInputForm");
this.add(form);
form.setOutputMarkupId(true);

FormComponent fc;

fc = new RequiredTextField("street", new AddressModel(new Model(address), AddressModelType.STREET_MODEL));
fc.add(StringValidator.maximumLength(30));
fc.setLabel(new ResourceModel("label.street"));
form.add(fc);

form.add(new AjaxButton("submitAddressInput", form){

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form){                
            System.out.println(address.toString());
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form){
            //
        }
    });

AjaxEventBehavior behavior = new AjaxEventBehavior("keyup"){

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            System.out.println(address.toString());
        }
    };

    form.add(behavior);

I created a little example about the problem.

Basically when the person inserts a value into the field called "street" then as you can expect from the code it activates behavior and runs the method onEvent(). onEvent() there will be print out of variable address. Unfortunately address.street value is NULL. So it prints out "Street: NULL".

But when the person clicks on the ajax button, which submits the data, then Wicket loads all the data from the form through AddressModel into address variable. In there the end result will be for example "Street: Bond street".

My question is that how I could init the process of saving data into the address variable in AjaxEventBehavior case?

Was it helpful?

Solution

Use AjaxFormComponentUpdatingBehavior which will submit the component's value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top