Alex Rivera | Logout

How to handle multiple submits before response is rendered?

Asked 2012-04-10T11:16:19.310
10

It has been reported from testing that it is occasionally possible to press a button more than once if the response is not rendered fast enough, causing several invocations of the back-end code, which we do not want.

Application is Java EE 6 Web Profile using JSF 2.0 inside Glassfish 3.1.1.

I was wondering how this should be properly dealt with, and have thought of a few scenarios:

  • Submitting should disable all buttons using javascript while response is being rendered.
  • A flag in the Session scope saying it is already active, so the sensitive code is skipped and just moves on to the re-rendering of the response for the previous submit.
  • A synchronized block delaying the processing until the previous request have finished. Then it should be detected that it has been already processed and skipped.
  • Using one of the "new" scopes like conversion to handle the detection?

My immediate gut feeling is that the best approach is to have sensitive code blocks atomic, but then the problem is with rendering the correct response.

How should I approach this?

Edit
Report

1 Answer

3

As Adrian mentioned, I would also use BlockUI. There is a BlockUI component from Primefaces. When you submit your forms through ajax, you could also use an overlay during the request. See Primefaces`s Ajax Status for an example.

answered 2012-04-10T12:46:32.573

Your Answer