javaajaxwicketwicket-1.6

Wicket onchange event returns the old value


I am attaching an onchange event using the Wicket framework. The problem is that the old value keeps being returned as the event is fired (Which makes sense). See code below.

What I want to do is get the "new" value of the select / dropbox after it has changed.

How can I achieve this?

    dropdown.add(new AjaxEventBehavior("onchange") {

        /**
         *
         * @param target
         */
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            Component component = getComponent();
            DropDownChoice dropdown = (DropDownChoice) component;

            String value = dropdown.getValue();//This brings back the old value…
        }
    })

Solution

  • You'll have to use an AjaxFormComponentUpdatingBehavior, otherwise the new value will not be submitted, then call getModelObject() to get hold of the new selection.