Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket: concurrent Ajax requests limited to one?

Tags:

ajax

wicket

Situation

In my Wicket application, I have a page which contains two tags. Each time a tab is selected, its content is fetched via Ajax so that every time you switch to a different tab its content it loaded fresh from the server.

On one of the tabs I have an input field which has an onblur event which saves the contents of the field via Ajax.

Problem

If the focus is on the input field and I click to a blank area of the page, the Ajax request it fired and the data saved.

If, instead of clicking on a blank area of the page, I click on the other tab, the Ajax request to save the input field is fired but not the Ajax request to switch tabs.

Is the number of concurrent Ajax requests limited in Wicket to one?

like image 426
SlappyTheFish Avatar asked May 02 '11 11:05

SlappyTheFish


2 Answers

Yes, concurrent requests to a page instance are limited to one. Wicket Ajax will queue subsequent Ajax requests in the client side channel. See the wicket Ajax debugger for details in your running application.

This is done to make building your application easier: no need to work around concurrency issues on the server. Page access is always one done from one single thread: the current active request thread. If we didn't do this, we would have to synchronize on the component tree and make the whole programming model go yuk.

like image 172
Martijn Dashorst Avatar answered Oct 31 '22 22:10

Martijn Dashorst


The problem was our AjaxIndicator which overlays a DIV over the entire page for the duration of each Ajax request. The "mouseup" (and consequently "click") events arrived when the overlay was in place, and thus lost. By holding the mouse button down and releasing it after the first Ajax request had completed and overlaying DIV removed, the second ajax request was fired.

It seems obvious now as the whole reason why we have such an overlay is to prevent users clicking while an Ajax request is running.

I think my solution will be to disable the ajax indicator on certain, very quick requests such as these where it makes no sense to have an indicator (disregarding the potential that requests could take much longer in case of unusually high server load).

like image 24
SlappyTheFish Avatar answered Oct 31 '22 21:10

SlappyTheFish