wicket - Wicket Dropdownchoice 不能改变选中的值
问题描述
我有 category1 和 category2 的两个 DropDownChoice 组件。我想在更改 category1 的选定值时更改 category2 的列表。但是在调用 category1.getModelObject() 方法时,category1 的更改值始终保持初始值。
private void addCategoryChoice(Form form) {
List<Category1> category1List = category1Impl.listProduct();
ChoiceRenderer renderer1=new ChoiceRenderer<Category1>() {
@Override
public Object getDisplayValue(Category1 value) {
return value.getName();
}
};
DropDownChoice<Category1> category1 = new DropDownChoice<Category1>("category1",
new Model<Category1>(category1List.get(1)) , category1List,renderer1);
category2List = category2Imple.listByCategory1Id(category1.getModelObject().getId());
ChoiceRenderer renderer2=new ChoiceRenderer<Category2>() {
@Override
public Object getDisplayValue(Category2 value) {
return value.getName();
}
};
DropDownChoice<Category2> category2 = new DropDownChoice("category2",category2List,renderer2);
form.add(category2);
category1.add(new AjaxEventBehavior("change") {
@Override
protected void onEvent(AjaxRequestTarget target) {
category2List.clear();
int id=category1.getModelObject().getId();
category2List.addAll(category2Imple.listByCategory1Id(Integer.valueOf(id)));
category2.setChoices(category2List);
}
});
form.add(category1);
}
解决方案
AjaxEventBehavior 不更新组件模型。您应该改用 OnChangeAjaxBehavior。
推荐阅读
- python - 使用python从包含存储在另一个列表中的短语的列表中查找句子
- javascript - 使用 axios 做出本机反应时出现错误 404 - 请求失败,状态码为 404
- java - 如何在运行 JSP 页面之前运行 Servlet?
- java - Spring批处理:Tasklet的测试用例-从测试类调用时,键未出现在实际类中
- jasmine - 为什么我在断言步骤中收到超时错误
- java - @OneToOne 单向级联没有被 sql 查询删除
- angular - Angular 9 Universal 和 SEO
- c++ - 使用 scanf 从文本文件行中读取多个整数
- .net - 存储原始数据以进行复杂计算
- matplotlib - 使用 twinx 时出现旋转 xtick 标签的问题