Hello,

I think the problem is just that you're calling setValues on your
"genericModelObject", which is set as the compoundpropertymodel for your
form, but you're not adding the form back to the ajax response - with the
AjaxRequestTarget, you're only adding the component "dropDownId" to get
re-rendered into the page, not the form with the updated model.  So, the
change made directly on the dropdown which is added to the ajaxRequestTarget
(calling setEnabled) is taking effect, but it's not finding the updated
model.  It should work if you add:
target.addComponent(get("formId"));

Hope that helps,
-Evan

-----Original Message-----
From: Gytis [mailto:lietuvis...@mail.ru] 
Sent: Friday, March 16, 2012 5:32 AM
To: users@wicket.apache.org
Subject: AjaxFormComponentUpdatingBehavior after validation problem

Hello, I have such a problem with AjaxFormComponentUpdatingBehavior. 
I have some DropDownChoice and a CheckBox on a Form. I need to make a change
to DropDown, when I click on CheckBox. But as I try to submit a Form, got
some error, and then click CheckBox DropDown doesn`t change. The code looks
like this: 

   DropDownChoice<SomeEnum> dropDownz = new
DropDownChoice<SomeEnum>("dropDownId",
                        Arrays.asList(SomeEnum.values()), new
EnumChoiceRenderer<SomeEnum>(this));
   getGenericModelObject().setValues(SomeEnum.FIRSTVALUE);
   CheckBox boxz = new CheckBox("BoxId");
   boxz.add(new AjaxFormComponentUpdatingBehavior("onchange")
                {
                        @Override
                        protected void onUpdate(AjaxRequestTarget target) {
                                if (boxz.getModelObject())
                                {
        
getGenericModelObject().setValues(SomeEnum.SECONDVALUE);
                                        get("dropDownId").setEnabled(false);
        
target.addComponent(get("dropDownId"));
                                }
                                else
                                {
                                        get("dropDownId").setEnabled(true);
        
target.addComponent(get("dropDownId"));
                                }
                        }
                        @Override
                        protected void onError(AjaxRequestTarget target,
RuntimeException e) {
                                if (boxz.getModelObject())
                                {
        
getGenericModelObject().setValues(SomeEnum.SECONDVALUE);
                                        get("dropDownId").setEnabled(false);
        
target.addComponent(get("dropDownId"));
                                }
                                else
                                {
                                        get("dropDownId").setEnabled(true);
        
target.addComponent(get("dropDownId"));
                                }
                                super.onError(target, e);
                        }
                });
     Form form = new Form("formId", getGenericModel());
     form.add(dropDownz);
     form.add(boxz);

So as I said, after form validation, if errors occur, it won`t change
dropdown to SECONDVALUE, but sets it as setEnabled(false), why this happens?

--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/AjaxFormComponentUpdatingBehavior
-after-validation-problem-tp4477705p4477705.html
Sent from the Users forum mailing list archive at Nabble.com.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to