3

I have a form containing just a TextField and a Button. I notice that if I set the text field as required and click on the button, I get the appropriate feedback message.

However, when I have an AjaxButton instead (which is what I need, because I need to execute a callback method with an AjaxRequestTarget), I do not see the feedback message, unless I reload. Upon debugging, I noticed that the onSubmit method of the form is called (the onError too), but the onSubmit method of the AjaxButton is not.

What do you suggest I do so that I can see the feedback message and call a callback method?

        Form<Void> form = new Form<>("form");

        // added the textfield too

        form.add(new AjaxButton("startButton") {
            private static final long serialVersionUID = 1L;

            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                // some action
                target.add(this);
            }

        });
        add(form);

        <form wicket:id="form">
            <table>
                <tbody>
                    <tr>
                        <!-- some stuff -->
                    </tr>
                    <tr>
                        <td><input type="submit" wicket:id="startButton" class="roundedButton"></input></td>
                    </tr>
                </tbody>
            </table>
        </form>
georgebax
  • 115
  • 1
  • 8

1 Answers1

3

I can't see your entire code but you might need to add the FeedbackPanel to AjaxRequestTarget when onError is triggered.

Andrea Del Bene
  • 2,521
  • 1
  • 15
  • 20
  • Thanks! My FeedbackPanel is added to the parent Page. I overrided `onError` of Form, got the AjaxRequestTarget from the Session and added the feedback panel. This worked, I am accepting the answer but I'm still uncertain as to why this didn't work in the first place. – georgebax Apr 26 '20 at 20:37
  • I'm happy you solved the problem. however it's quite strange that you can't use onSubmit/onError from AjaxButton. You can try to explicetly set this button as form submitter with 'form.setDefaultButton(ajaxButton)' or passing form to AjaxButton constructor (with 'new AjaxButton("startButton", form)') Good luck! – Andrea Del Bene Apr 27 '20 at 12:31