开发者

How to read listbox's PropertyModel state from onUpdate() event of AjaxCheckBox - Apache Wicket

Problem: user made some selection in the multi-selection listbox, then pressed a checkbox, and selection got lost. I need the selection to be preserved.

I have a report wizard which extends (wicket.extensions.wizard.Wizard) I have a step which extends WizardStep.WizardStep On this step I have a mutli-selection box which extends wicket.markup.html.form.ListMultipleChoice I add it as follows:


final ChooseListMultipleChoice allPlansChoiceField = new ChooseListMultipleChoice(PLANS_SELECT_ALL_PLANS_LIST, new PropertyModel(this, "selectedAllPlans"), allPlans);
allPlansChoiceField.setOutputMarkupId(true);
add(allPlansChoiceField);

and I also have AjaxCheckBox (wicket.ajax.markup.html.form.AjaxCheckBox) Used like this:


  AjaxCheckBox displayArchived = new AjaxCheckBox(DISPLAY_ARCHIVED){
            protected void onUpdate(final AjaxRequestTarget target) {
                allPlans.clear();
                final boolean isDisplayArchived = rawReportFilterInput.isDisplayArchived();
                List listAllPlan = projectFacade.listActiveAndClosingPlans(isSort, isDisplayArchived);
              开发者_如何学运维  allPlans.addAll(listAllPlan);
                target.addComponent(allPlansChoiceField);
            }
        };
        add(displayArchived);

inside the onUpdate method the model "selectedAllPlans" is not updated with current user selection. For instance, if I had just a simple ajax submit buttom, then it would have triggered the onSubmit event and all form data would have been passed and "selectedAllPlans" would be populated with user selection. I need the exact same behaviour when user checks/unchecks the AjaxCheckBox. So far, I haven't been able to make it working, model is always size = 0.

MarkUp:

<div class="effortsReport" style="height: 220px;">
<table>
    <tr>
        <input type="checkbox" wicket:id="plansSelect.displayArchived">
        <br><div class="fixed_select"><select wicket:id="allPlansList"/></div></td>
    </tr>
</table>
</div>

I would appreciate some advise, possible solutions. Best regards, Oleg


Okay I figured it out, just do this:

allPlansChoiceField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(allPlansChoiceField);
        }
    });

and that's all. You do not even need to store/restore the state, it just works. Yes it took time to find this out, but it's possible and easy in the end. Gotta love Wicket.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜