Kitching Simon wrote:

> Hi,
>
> I currently have a model-1 web application
> ie in which the .jsp pages are responsible
> for invoking the business logic.
>
> I am planning to move the webapp to struts,
> for all the obvious and traditional reasons.
> However, there is one nice feature of the
> current code that I can't see how to perform
> inside an MVC framework like struts:
>
> On submitting a particular form, there is a
> sequence of 4 operations to perform, each of
> which takes somewhere between 5 and 30
> seconds to perform. Currently, what is done is
> to generate an almost complete HTML page,
> and force it to be flushed to the browser; as
> each long-duration step starts and completes,
> a fragment of page containing CSS-positioned
> html/ javascript is flushed to the browser. The
> effect is very nice - a list of the steps appears
> on the screen, an hourglass appears next to
> each step as it starts, and a tick or error message
> appears next to each one as it completes.
>
> Does anyone have any idea how to generate the
> same sort of effect (essentially alternating between
> business logic and presentation output) in struts?
>

As you've gathered, a model 2 approach is not amenable to using flushing to show
progress.  A strategy that might work better is something like this, in the
initial Action that starts all of the work:

* Fire off a background thread to do the long-duration work.
* Give this thread access to the user's session, so it can
  update a status variable when it is done
* Return a "work in progress .. click here to check for completion"
  page, which returns to the same action
* When the action is entered, it will check to see that a
  background thread is currently running, so it will display
  another "work in progress" page, or the final results, depending
  on what's been done so far.
* When the background thread completes its work, it updates
  the final status and exits.

Variations on the theme:
* The status variable need not be binary -- for a multiple
  stage background operation, it could be a state identifier,
  or a percentage completed, or something like that, so you
  can be more descriptive on the "in progress" page.
* You might want to generate a meta refresh tag on the
  "in progress" page, so that the user doesn't have to remember
  to hit the link.

>
> Thanks in advance,
>
> Simon

Craig


Reply via email to