I can't seem to get my models to update when I submit a form using AjaxButton. Originally my code looked like this, and I though it should just work, but when you click the submit link parentService is null and bundles and elements are empty lists.:
class AddServices extends BasePage { AbacusService parentService = new AbacusService(); List<ServicePlan> bundles = new ArrayList(); List<ServicePlan> elements = new ArrayList(); public AddServices(final ModalWindow window, final OrderModel order) { add(new Label("id", new Model(order.getId()))); Form form = new Form("form"); add(form); final FeedbackPanel feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); form.add(feedback); form.add(new DropDownChoice("parent", new PropertyModel(this, "parentService"), Application.orderDao.getPossibleParents(order.getId()), new ChoiceRenderer("fullName"))); form.add(new ListMultipleChoice("bundles", new PropertyModel(this, "bundles"), Application.orderDao.getBundleTemplates(), new ChoiceRenderer("serviceTypeAndName"))); form.add(new ListMultipleChoice("elements", new PropertyModel(this, "elements"), Application.orderDao.getBundleTemplates(), new ChoiceRenderer("serviceTypeAndName"))); AjaxButton submit = new AjaxButton("submit", form) { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { info("submitting form"); info("parent =" + parentService.toString()); info("elements = " + elements.toString()); info("bundles = " + bundles.toString()); //Application.orderDao.addServices(elements, order.getId(), parent, null); //window.close(target); } @Override protected void onError(AjaxRequestTarget target, Form form) { error("Grrr Arrg"); target.addComponent(feedback); } }; form.add(submit); } } So, I thought maybe I was expecting too much of AjaxButton and manually updated these variables in an AjaxFormComponentUpdatingBehavior like so: ListMultipleChoice bundleChoice = new ListMultipleChoice("bundles", new Model(), Application.orderDao.getBundleTemplates(), new ChoiceRenderer("serviceTypeAndName")); bundleChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { info("model:" + this.getComponent().getModelObject().toString()); bundles = (List<ServicePlan>) this.getComponent().getModelObject(); target.addComponent(feedback); } }); form.add(bundleChoice); Now when I select things off the components the feedback panel updates with the things I've selected, but when it gets to the submit method I still have empty lists and a null, and I am seriously confused as to why. Everything works properly if I forgo submitting via Ajax and just override the form's onSubmit(), but I'd like to shove this page into a modal window and so need the ajax bit to close the window.. What am I missing?