views:

377

answers:

2

Hi,

I am implementing a functionality in my web app such that a client can generate the report by entering some data and clicking on the submit button.

The problem is that report generation takes lot of time and the report might not generate if the user entered data is wrong.

The complete report generation task has many sub-tasks and I want when the client presses submit then just below that page I want to show the status/progress of the report generation tasks splitted in various sub-tasks like

- Validating input data ------ Done
- Fetching the data     ------ In Progress
 and so on,

How can I achieve this using Struts2, jQuery in the web layer?

Any help will be greatly appreciated.

Thanks

+1  A: 

We had a similar problem. The transaction normally takes 20 seconds, sometimes over a minute. We thought there would be easier solutions but we ended up with a scheme like this,

  1. When the long running request is received, a session is created and a new thread is spawn to handle the request.
  2. A page is immediately returned with text to display "Collecting data ...". The page contains a timer to refresh itself every second. The reload URL contains the session ID (we don't use HttpSession) in the query parameter.
  3. When the action handler sees the request with a session ID, it knows the session is started, check a state variable being updated by the working thread. If it's not done, it updates the page with new status "Retrieving data from DB1 ...". There is flickering when this is done as reload. If you care, you can use AJAX to update the status.
  4. When the working thread is done and the page is ready to deliver, the call simply returns the result.

We ran into some problem with the load-balancer. For the scheme to work, every reload must come back to the same server. Fortunately, the load-balancer supports sticky routing based on our session id.

ZZ Coder
Thanks ZZ Coder..But I have a doubt - In 3 above, how do you query the state variable when the action has the sessionId in it?
peakit
When you create the session, you have to save the session object in a map somewhere. You can use servletContext.setAttribute(sid, obj). In step 3, just do servletContext.getAttribute(sid) to retrieve the session object, which contains the state.
ZZ Coder
Cleared my doubt.. thanks for sharing your idea..
peakit
A: 

Take a look at the Struts2 ExecuteAndWait interceptor. http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html

Dusty Pearce