Reputation: 47
I am adding a warning message using form.warn method but the warning message is not getting displayed. how do you add warning message on a wicket form
public class FormPanel extends BreadCrumbPanel {
public FormPanel(String id, IBreadCrumbModel breadCrumbModel)
{
super(id, breadCrumbModel);
Form<?> form = new Form<Void>("form");
form.add(new SaveButton("save"));
form.add(new FeedbackPanel("feedback"));
}
private class SaveButton extends Button {
private static final long serialVersionUID = 1L;
public SaveButton(String id) {
super(id);
}
@Override
public void onSubmit() {
validate(getForm());
}
}
validate(Form<?> form){
if(some logic)
form.warn(“message”);
}
}
Upvotes: 1
Views: 529
Reputation: 17533
You better move your validation logic to IValidator#validate()
or IFormValidator#validate()
.
Currently you call it in Button#onSubmit()
. That means Wicket believes everything is valid in your form fields and calls the last step - onSubmit()
. Usually after onSubmit()
you either render a completely different page or a new instance of the current page. In both cases the current page instance is lost together with its Form and its feedback messages.
If IValidator#validate()
fails then Wicket will call onError()
instead and re-render the current page instance.
Upvotes: 2