How to change Wicket behaviour on Page Expired

2019-07-15 19:47发布

问题:

We have a wicket application for our main website. Lately we have implemented a mobile version of the site. The mobile version is special in that it is deployed inside a native app wrapper to some mobile devices and not connected to the rest of the page through links because it is not supposed to be normally visible to web users.

The mobile page makes use of ajax and is therefore prone to receive "Page expired" errors for example when we restart the application on the server.

Since that page is not connected to the rest of the application through links I do not want our standard "Page expired" behaviour. Is it possible to override or intercept this behaviour for the pages belonging to the mobile part of the site? For example I could like to be able to configure the pages to simply reload on a "Page expired" error.

回答1:

Yes,

getApplicationSettings().setPageExpiredErrorPage(YourPage.class)

YourPage.class can then for instance be your HomePage or another Page that depending on it being a request from a mobile device does something else.

If you would like to reload the Page the user was one then it becomes a bit less trivial. Reloading the Page is not possible since you are not on the page anymore. You could have a look at IRequestCycleListener and overriding onException and handle PageExpiredException yourself but it is a dangerous road you travel if you simply reload your Page. Navigating to the home (or other) page seems more logical. I assume you are not restarting your server 100 times per day...



标签: wicket