You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sebastian Lichtenfels <Se...@tomtec.de> on 2020/03/06 09:34:06 UTC

Preventing AJAX behavior to execute during page reload

Hi all,

I have a problem with an AJAX behavior that I have on a stateful page. The behavior is triggered by the user by clicking a button (the button is outside my control).
The behavior then does some backend action on the server and afterwards reloads the page (by calling RequestCycle.get().setResponsePage(page.getPageClass(), page.getPageParameters());, where page is the the current page).
My problem now is that it can happen that the user clicks the button twice which results in the following sequence of calls:

1.       First behavior is triggered on page version 1

2.       Backend action is done

3.       Server sends 302 to reload page

4.       Second behavior is triggered (still for page version 1)

5.       Backend is done for second behavior

6.       Client cancels AJAX request for second behavior, because of the page redirect -> so no additional page reload here

7.       Page render is triggered by the page reload

My goal is to always reload the page if the backend action is triggered, because the page's state depends on the backend state.
So either the second behavior should not be triggered at all or it should be correctly executed (meaning backend action AND page reload should be triggered).
How can I achieve this?

Best regards,
Sebastian

Re: Preventing AJAX behavior to execute during page reload

Posted by Bas Gooren <ba...@iswd.nl>.
Hi Sebastian,

I’m confused: you say you have a stateful page but redirect in a stateless
manner (to a new page instance).

I think this is relatively easy to fix if you remain stateful, because (a)
wicket guards against concurrent acces to a single page instance and (b)
you can track in the page state if an action was executed or not.

May I ask why you are not simply calling setResponsePage(getPage())?

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 6 maart 2020 bij 10:58:59, Sebastian Lichtenfels (
sebastian.lichtenfels@tomtec.de) schreef:

Hi all,

I have a problem with an AJAX behavior that I have on a stateful page. The
behavior is triggered by the user by clicking a button (the button is
outside my control).
The behavior then does some backend action on the server and afterwards
reloads the page (by calling
RequestCycle.get().setResponsePage(page.getPageClass(),
page.getPageParameters());, where page is the the current page).
My problem now is that it can happen that the user clicks the button twice
which results in the following sequence of calls:

1. First behavior is triggered on page version 1

2. Backend action is done

3. Server sends 302 to reload page

4. Second behavior is triggered (still for page version 1)

5. Backend is done for second behavior

6. Client cancels AJAX request for second behavior, because of the page
redirect -> so no additional page reload here

7. Page render is triggered by the page reload

My goal is to always reload the page if the backend action is triggered,
because the page's state depends on the backend state.
So either the second behavior should not be triggered at all or it should
be correctly executed (meaning backend action AND page reload should be
triggered).
How can I achieve this?

Best regards,
Sebastian