I have some logic in onSubmit of the button (which is in Form), which may fail, so I would like to show a message using error(myMessage)
. But it doesn't work, and it seems that it is normal:
Feedback panel added but does not show all messages
Is there any possibility to render feedback panels with errors reported in onSubmit?
There is no ajax used on the page. I am using wicket 1.5.6
EDIT:
MyPage.java
public class MyPage extends WebPage {
private static final Logger logger = Logger.getLogger(MyPage.class);
private static final long serialVersionUID = -8874964120018036584L;
public MyPage(PageParameters parameters) {
super(parameters);
logger.debug("Creating new login page");
add(new MyLoginForm("loginForm"));
}
}
MyLoginForm.java
public class MyLoginForm extends StatelessForm<Void> {
private static final Logger logger = Logger.getLogger(MyLoginForm.class);
private static final long serialVersionUID = -8694389090804630170L;
private MyUser user = new MyUser();
public MyLoginForm(String id) {
super(id);
setOutputMarkupId(true);
logger.debug("Creating new stateless login form");
add(new RequiredTextField<String>("login", new PropertyModel<String>(user, "login")));
add(new PasswordTextField("password", new PropertyModel<String>(user, "password")));
add(new Button("submit"));
add(new FeedbackPanel("feedback"));
}
@Override
public void onSubmit() {
info("test info");
}
}
MyPage.html
<body>
<form wicket:id="loginForm">
<fieldset>
<legend><wicket:message key="form.login.legend"/></legend>
<input type="text" wicket:id="login" />
<input type="password" wicket:id="password" />
<input type="submit" wicket:id="submit" />
<span wicket:id="feedback"></span>
</fieldset>
</form>
</body>
catalina.out
16 May 2012 15:24:20:860 WARN [http-8080-2] [WebSession:135] Component-targetted feedback message was left unrendered. This could be because you are missing a FeedbackPanel on the page. Message: [FeedbackMessage message = "test info", reporter = loginForm, level = INFO]
The same happens when I try to overwrite the onSubmit method in Button instead of the one in MyLoginForm...
You need to add a FeedbackPanel to your Page. Feedback messages 'bubble' up in the component hierarchie. The easiest way is to have one feedbackpanel on your page.
But, you can also display errors close to the FormComponent that reports the error. See this pdf for inspiration or for a possible implementation.
Edit: I just build a very simple test, using the wicket quickstart. Changed the HomePage as below and it worked (I saw all error / info messages)
html:
Java:
Edit 2: It turns out, that a StatelessForm is used (I overlooked that detail). Switching back to (normal) Form, the messages should be displayed correctly.