Thanks Igor, I've determined that something is not playing nicely here.

The larger picture is this - user visits a page and clicks on Add to add a
widget to the database. I pop up a ModalWindow with a form on it. User can
(a) submit form, (b) cancel button (c) cancel link.

I'd like to close the form on a successful submission or if the user clicks
on either 'cancel' option.

        private static class AreaEditorForm extends Form<Area> {
                private static final long serialVersionUID = 1L;

                public AreaEditorForm(final String id,
                                final Area area,
                                final ModalWindow modal) {
                        super(id, new CompoundPropertyModel<Area>(area));
                        final TextField<String> name = new 
TextField<String>("name");
                        add(name);
                        name.setRequired(true);
                        name.add(new DefaultFocusBehavior());

                        final TextArea<String> summary = new 
TextArea<String>("summary");
                        summary.setRequired(true);
                        add(summary);

                        add(new AjaxButton("submit.button", 
AreaEditorForm.this) {
                                private static final long serialVersionUID = 1L;

                                @Override
                                protected void onSubmit(final AjaxRequestTarget 
target,
                                                final Form<?> form) {
                                        System.out.println("submit.button 
AjaxButton.onSubmit(target)");
                                        modal.close(target);
                                }
                        });

                        final AjaxButton cancel = new 
AjaxButton("cancel.button",
AreaEditorForm.this) {
                                private static final long serialVersionUID = 1L;

                                @Override
                                protected void onSubmit(final AjaxRequestTarget 
target,
                                                final Form<?> form) {
                                        System.out.println("cancel.button 
AjaxButton.onSubmit(target)");
                                        modal.close(target);
                                }
                        };
                        cancel.setDefaultFormProcessing(false);
                        add(cancel);

                        add(new AjaxLink<Void>("cancel.link") {
                                private static final long serialVersionUID = 1L;

                                @Override
                                public void onClick(final AjaxRequestTarget 
target) {
                                        System.out.println("AjaxLink.onClick");
                                        modal.close(target);
                                }
                        });
                }

                @Override
                protected void delegateSubmit(final IFormSubmittingComponent
submittingComponent) {
                        System.out.println("Form.delegateSubmit");
                        super.delegateSubmit(submittingComponent);
                }

                @Override
                protected void onSubmit() {
                        System.out.println("Form.onSubmit");
                        super.onSubmit();
                }

        }


For some reason, neither AjaxButton for cancel or submit can close the
window. The AjaxLink can - and that works in my situation for 'cancelling'
but I have to be able to close the window after a successful submission and
that code is not working in the onSubmit handlers (of either button).

Am I missing a wire?

One other anomaly - I can see the screen flicker on each submission or
cancel (ie: I can tell a request is hitting the server). But, regardless of
submission or canceling button, validation ALWAYS occurs. Per the required
fields in the form - canceling does not seem to skip the validation
eventhough I've included: cancel.setDefaultFormProcessing(false);

Another anomaly, "AjaxButton: A button that submits the form via ajax. Since
this button takes the form as a constructor argument it does not need to be
added to it unlike the Button component." .... but if I remove this line:

    add(cancel);

wicket complains "WicketMessage: Unable to find component with id
'cancel.button' ..."

If I place data in the two fields and then click on cancel,
"Form.delegateSubmit" logs to the console followed by "Form.onSubmit" ...
but I don't initially see "cancel.button ..." log to the console. In fact, I
click the cancel button 4 more times before I actually see it echo it's
println to the console. It is odd. Then I don't see that line for 4 more
trys ... and then it happens again. If I vary the pace, I can get it to show
up unpredictably at different times.

The docs also mention: "The default when there is a submitting
IFormSubmittingComponent is to first call onSubmit on that Component," ...
but I'm seeing the opposite here correct (assuming the button the submitting
component).

Here is a series of 15 clicks on the "Cancel" Button:

Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
cancel.button AjaxButton.onSubmit(target)
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
cancel.button AjaxButton.onSubmit(target)
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
cancel.button AjaxButton.onSubmit(target)
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
cancel.button AjaxButton.onSubmit(target)

And the same thing goes for the Submit button. Sometimes it echoes,
sometimes it doesn't and it it never actually closes the window.

Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
submit.button AjaxButton.onSubmit(target)
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
submit.button AjaxButton.onSubmit(target)
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
submit.button AjaxButton.onSubmit(target)
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
Form.delegateSubmit
Form.onSubmit
submit.button AjaxButton.onSubmit(target)


HTML here:

        <form class="standard" wicket:id="form">
        <table class="top">
        <tr>
                <th>Name</th>
                <td><input wicket:id="name" type="text" name="name" size="56"
maxlength="80" value="abcd"></input></td>
        </tr>
        <tr>
                <th>Summary</th>
                <td><textarea wicket:id="summary" name="summary"
rows="6">abcd</textarea></td>
        </tr>
        <tr>
                <th>&nbsp;</th>
                <td>
                        <input wicket:id="submit.button" type="submit"
wicket:message="value:Application.saveButton.label"/>
                        <input wicket:id="cancel.button" type="submit"
wicket:message="value:Application.cancelButton.label"/>
                         # <wicket:message 
key="Application.cancelButton.label"/> 
                </td>
        </tr>
        </table>
        </form>


Any thoughts would be appreciated.

-Luther

-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Cancelling-ala-AjaxLink-vs-AjaxButton-tp2717635p2718130.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to