0

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

Community
  • 1
  • 1
Adam Pierzchała
  • 2,244
  • 4
  • 30
  • 32

3 Answers3

2

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.

bert
  • 7,566
  • 3
  • 31
  • 47
  • if I move a feedback panel from MyLoginForm to MyPage, it makes no difference (I moved it in markup too). I think I don't understand what you mean... – Adam Pierzchała May 17 '12 at 09:00
  • @Adam Pierzchala: My bad. I did not spot the feedbackpanel in your code. I will do some testing and report back later. – bert May 18 '12 at 11:50
  • Thank you, I'm waiting patiently for results :). Actually, I don't feel a newbie in wicket, I used to do much in wicket 1.4. I don't think it changed so dramatically in 1.5, so there must be some trivial mistake that I am making... – Adam Pierzchała May 18 '12 at 12:09
  • Sorry for the long delay, I was away from home. I updated my answer. – bert May 21 '12 at 19:45
  • I just have a thought... (I'm away from home, so I can't check) - could it be because I inherit from StatelessForm, instead of Form? – Adam Pierzchała May 22 '12 at 12:18
  • @AdamPierzchała: Correct. I changed from Form to StatelessForm and the feedback messages where not displayed anymore. Somehow, this makes sense (as the messages mean state) – bert May 22 '12 at 19:40
  • Then... Aaah I see! I was wondering why [SignInForm](http://grepcode.com/file_/repo1.maven.org/maven2/org.apache.wicket/wicket-auth-roles/1.5.4/org/apache/wicket/authroles/authentication/panel/SignInPanel.java/?v=source) inherits from StatelessForm and works. And now that I looked deeply into source code, I think it works because it's the Page (not the Form) that executes `error()` method. But doesn't it make the page statefull? – Adam Pierzchała May 23 '12 at 06:51
0

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

Jacek Cz
  • 1,872
  • 1
  • 15
  • 22
0

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.

eaglei22
  • 2,589
  • 1
  • 38
  • 53