英文:
Wicket DropDownChoice onSelectionChanged method removed after version update
问题
我被指定为开发人员,负责将我们的旧 wicket 应用程序从6.x升级到8.x。我正在逐个解决多个错误,但由于我以前从未使用过 wicket,所以有一个错误我无法继续下去。
在6.x版本中,它使用了带有重写 onSelectionChanged 方法的 DropDownChoice,但在8.x版本中不再存在,我无法找到任何关于废弃的信息(已查阅了7.x版本...),所以看起来他们只是将它删除了...那么在这种情况下我有哪些替代选择呢?上述的代码:
booleanType = new DropDownChoice<BooleanType>("booleanType", new PropertyModel<>(this, "selectedBooleanType"), booleanTypes) {
@Override
protected void onSelectionChanged(BooleanType newSelection) {
super.onSelectionChanged(newSelection);
selectedBooleanType = newSelection;
}
};
编辑:
我稍后才发现了类似的问题
https://stackoverflow.com/questions/60542299/wicket-6-to-8-upgrade-radiogroup-onselectionchanged-replacement?rq=1
对于那些想知道如何更新值的人,因为它不再作为方法的参数传入:
selectedType = (YourChoiceType) super.getFormComponent().getDefaultModelObject();
英文:
I was designated as a developer to upgrade our old wicket app from 6.x to 8.x. I am resolving multiple errors one by one, but (since I never worked with wicket) one I am unable to move on with.
In version 6.x it had DropDownChoice with overriden onSelectionChanged which no longer exists in version 8.x and I am unable to find any info about deprecation (going through 7.x versions...) so it seems they just removed it .. what are my alternatives here? The aforementioned code:
booleanType = new DropDownChoice<BooleanType>("booleanType", new PropertyModel<>(this, "selectedBooleanType"), booleanTypes) {
@Override
protected void onSelectionChanged(BooleanType newSelection) {
super.onSelectionChanged(newSelection);
selectedBooleanType = newSelection;
}
};
EDIT:
Similar question that I found only later
https://stackoverflow.com/questions/60542299/wicket-6-to-8-upgrade-radiogroup-onselectionchanged-replacement?rq=1
for those wondering how to update the value since it is not coming as an argument of the method anymore:
selectedType = (YourChoiceType) super.getFormComponent().getDefaultModelObject();
答案1
得分: 4
wantOnSelectionChangedNotifications
被移至FormComponentUpdatingBehavior
。根据更新日志:
// Wicket 7.x
new CheckBox("id", model) {
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
protected void onSelectionChanged(Boolean newSelection) {
// 做一些操作,页面将被重新渲染;
}
};
// Wicket 8.x
new CheckBox("id", model)
.add(new FormComponentUpdatingBehavior() {
protected void onUpdate() {
// 做一些操作,页面将被重新渲染;
}
protected void onError(RuntimeException ex) {
super.onError(ex);
}
});
(此示例使用CheckBox
,但同样适用于DropDownChoice
)。
有关另一个示例,请参阅维基。
英文:
wantOnSelectionChangedNotifications
moved to FormComponentUpdatingBehavior
. From the changelog:
// Wicket 7.x
new CheckBox("id", model) {
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
protected void onSelectionChanged(Boolean newSelection) {
// do something, page will be rerendered;
}
};
// Wicket 8.x
new CheckBox("id", model)
.add(new FormComponentUpdatingBehavior() {
protected void onUpdate() {
// do something, page will be rerendered;
}
protected void onError(RuntimeException ex) {
super.onError(ex);
}
});
(The example uses a CheckBox
but it also applies to DropDownChoice
).
For another example see the wiki.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论