Error in onSubmit, feedback not rendering

8.5k Views Asked by At

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...

3

There are 3 best solutions below

7
On BEST ANSWER

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:

<form wicket:id="form">
            <div wicket:id="feedback"></div>
            <input wicket:id="submit" type="button" value="submit">

</form>

Java:

Form<Void> form = new Form<Void>("form") {
        @Override
        protected void onSubmit() {
            super.onSubmit();
            error("test error from form");
            error("test info from form");
        }
    };
    add(form);
    form.add(new FeedbackPanel("feedback"));
    form.add(new SubmitLink("submit") {
        @Override
        public void onSubmit() {
            super.onSubmit();
            error("an error occurred in button submit");
            info("test info from the button");
        }
    });

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.

0
On

I have checked twice, Wicket 1.5.6 FeedbackPanel (and SignInForm where I have problem) works worse than 1.5.4 I have no idea, what is backgroud of this behaviour.

EDIT: version 1.5.5 work good.

EDIT2: https://issues.apache.org/jira/browse/WICKET-4536

0
On

I found another way for anyone else who stumbles into this issue..

I have a base class that I inherit from and then I have the feedback messages print out as part of the base class.. I too ran into this issue, and just had a method inside my base class return an instance of itself (return this), and then I just access the info method through this method... so, getMethod().info("some message").. and it worked for me. My feedbackPanel is also set in the base class..

So I'd imagine you can do the same thing.. Just get access to an instance of the page you want to stamp the feedback message to.