Wicket: addOrReplace() inside Form's onSubmit()

Master_T

I have a wicket Form inside a page, declared like this:

protected void onBeforeRender() {
    Form<Void> frm = new Form<Void>("frm") {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit() {
                super.onSubmit();
                doSomething();
            }
        };

    //other stuff...
    addOrReplace(frm);
}

doSomething is a method in the page itself. Inside that method I do:

private void doSomething(){
    //stuff...
    addOrReplace(new Label("labelID", "Some text"));
}

The problem is that the call to addOrReplace does not work. I don't see the text added to the page. It only shows up if I refresh.

How can I make calls to addOrReplace work from inside a onSubmit() callback?

svenmeier

Sounds like you're working with AjaxButtons. You'll have to update the component or any of its parents to make the change visible in the browser:

ajaxRequestTarget.add(frm);

Remember to call #setOutputMarkupId(true) on the component you want to update via Ajax:

frm.setOutputMarkupId(true);
addOrReplace(frm);

To get hold of the AjaxRequestTarget you could override AjaxButton#onSubmit(AjaxRequestTarget, Form) and call doSomething from there - passing the AjaxRequestTarget to any method which has to update something.

Alternatively you can always call #getRequestCycle().find(AjaxRequestTarget.class) to get the current AjaxRequestTarget.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Wicket: addOrReplace() inside Form's onSubmit()

From Dev

A form's "action" and "onsubmit": Which executes first?

From Dev

How to fire the HTML form's onsubmit event?

From Dev

How to get the AjaxRequestTarget inside Wicket's onBeforeRender() method of a component?

From Dev

Making form's onsubmit to work only for particular submits

From Dev

Making form's onsubmit to work only for particular submits

From Dev

How to bind anonymous function to form's onsubmit and then access that form's contents for AJAX submit?

From Dev

Wicket Panel inside of a Fragment

From Dev

Form 'onsubmit' not getting called

From Dev

jQuery .validate() and form onsubmit

From Dev

Form.onsubmit not working

From Dev

form onsubmit ignores action

From Dev

Reusable DropDownChoice in Wicket Form

From Dev

Reusable DropDownChoice in Wicket Form

From Dev

Wicket fails to reload the page onSubmit when the page contains iframe

From Dev

Validation function in onsubmit form tag

From Dev

Form onsubmit being completely ignored

From Dev

Prevent form submission in the onsubmit event

From Dev

onsubmit and confirm always processing form?

From Dev

Form validation not working using onsubmit

From Dev

Where to add onsubmit to a form in Javascript

From Dev

Form Action & Javascript Onsubmit issue

From Dev

onsubmit and confirm always processing form?

From Dev

Form onsubmit="" with confirm window not working

From Dev

form onsubmit doesnt work properly

From Dev

Form attribute "onsubmit" not working properly

From Dev

Redux form unmounting component onSubmit

From Dev

Wicket: set JodaDateTime from form

From Dev

How to validate wicket form sequencly

Related Related

HotTag

Archive