我有一个包含dateTimeField和ListView的表单。ListView看起来像这样:
final ListView<String> countryView = new ListView<String>("country", model.<List<String>>bind("country")) {
@Override
protected void populateItem(final ListItem<String> item) {
final String country = item.getModelObject();
item.add(new ValidationDisplayableLabel("country", country, new String[] { modelPath }));
item.add(new AjaxLink("deleteLink") {
@Override
public void onClick(AjaxRequestTarget target) {
model.getObject().getCountry().remove(country);
if (issPeriod) {
addButton.setVisible(true);
countryTextField.setVisible(true);
findButton.setVisible(true);
}
if (target != null)
target.addComponent(rowPanel);
}
});
}
};
countryTextField = new ValidationDisplayableTextField("countryCodeInput", model.bind("oneCountry"), "job.country.value");
**countryView.setReuseItems(true);**
rowPanel.add(countryView);
rowPanel.add(countryTextField);
addButton.setOutputMarkupPlaceholderTag(true);
rowPanel.add(addButton);
添加按钮看起来像这样:
AjaxSubmitLink addButton = new AjaxSubmitLink(LinkNames.addCountry.toString()) {
@Override
public void onSubmit(AjaxRequestTarget target, Form form) {
if (model.getObject().getOneCountry() != null)
addCountry();
if (target != null)
target.addComponent(rowPanel);
target.addComponent(form.getPage().get("feedbackPanel"));
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
onSubmit(target, form);
}
};
事实是,当我在dateTimeField中失败(例如将小时设置为100),在countryTextField中输入国家代码并按addButton时,它会在反馈面板中显示验证消息,指出小时范围不正确,但不添加该国家。这是因为我的模型没有更新。也许有一种方法可以手动更新它?因此,即使仍然可以更新country listView,也会显示验证消息?
整个表单的提交是在另一个按钮上完成的,因此逻辑上即使在dateTimeField中存在验证错误,也可以添加国家。
谢谢!
附言:我已经阅读了很多关于类似问题的帖子,但大多数帖子都是通过.setReuseItems(true)解决的,但在我的情况下无法解决。
附言:Apache wicket 1.4.17