我正在使用BeanValidation for Form输入和AjaxFallbackButton来提交表单。和FeedbackPanel显示错误。当我提供无效输入时,表单不会提交但反馈面板没有显示。
onError,form.getFeedbackMessages()返回空数组。
Wicket版本6.18.0。
以下是代码:
Form<Address> form = getForm();
add(form);
FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackMessage");
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
public Form<Address> getForm() {
CompoundPropertyModel<Address> model = new CompoundPropertyModel<Address>(address);
final Form<Address> form = new Form<Address>("addressForm", model);
form.add(new Label("fNameLabel", new ResourceModel("fNameLabel")));
form.add(new Label("lNameLabel", new ResourceModel("lNameLabel")));
form.add(new Label("workLabel", new ResourceModel("workLabel")));
form.add(new Label("homeLabel", new ResourceModel("homeLabel")));
form.add(new TextField<String>("firstName").add(new PropertyValidator<String>()));
form.add(new TextField<String>("lastName").add(new PropertyValidator<String>()));
form.add(new TextField<String>("homeLocation").add(new PropertyValidator<String>()));
form.add(new TextField<String>("workLocation").add(new PropertyValidator<String>()));
form.add(new AjaxFallbackButton("submit", form) {
/**
*
*/
private static final long serialVersionUID = 6672729206839722437L;
@Override
protected void onError(final AjaxRequestTarget target, final Form form) {
Page page = target.getPage();
for (Component component : page.visitChildren()) {
String markupId = component.getMarkupId();
if (markupId.contains("feedbackMessage")) {
if (form.hasFeedbackMessage()) {
System.out.println(form.getFeedbackMessages());
}
}
}
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
if (address.getFirstName() != null) {
AddressGenerator.getInstance().add(address);
modalWindow.closeCurrent(target);
}
}
});
return form;
}
表格在ModalWindow中。
答案 0 :(得分:0)
Component#getFeedbackMessages()
会返回此组件实例的仅消息。它没有访问孩子们!
使用以下命令更新onError()
方法
@Override
protected void onError(final AjaxRequestTarget target, final Form form) {
target.add(feedbackPanel);
}
您可以使用if (form.hasError())
,但由于您在AjaxFallbackButton#onError()
,这意味着存在错误。