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:
我有一个扩展的报告向导(wicket.extensions.wizard.Wizard)我有一个扩展WizardStep.WizardStep的步骤在这一步我有一个mutli选择框扩展wicket.markup.html.form.ListMultipleChoice我添加为如下:
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(wicket.ajax.markup.html.form.AjaxCheckBox)像这样使用:
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.
在onUpdate方法中,模型“selectedAllPlans”不会使用当前用户选择进行更新。例如,如果我只有一个简单的ajax submit buttom,那么它将触发onSubmit事件并且所有表单数据都将被传递,并且“selectedAllPlans”将填充用户选择。当用户检查/取消选中AjaxCheckBox时,我需要完全相同的行为。到目前为止,我还没能使它工作,模型总是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
我会很感激一些建议,可能的解决方案。最诚挚的问候,奥列格
1 个解决方案
#1
1
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.
就这样。你甚至不需要存储/恢复状态,它只是工作。是的,需要时间才能找到它,但最终可能也很容易。一定要喜欢Wicket。
#1
1
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.
就这样。你甚至不需要存储/恢复状态,它只是工作。是的,需要时间才能找到它,但最终可能也很容易。一定要喜欢Wicket。