aspose file tools*
The moose likes JSF and the fly likes How to cancell long-runnig actionListener /stored proc. call/  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to cancell long-runnig actionListener /stored proc. call/  " Watch "How to cancell long-runnig actionListener /stored proc. call/  " New topic
Author

How to cancell long-runnig actionListener /stored proc. call/

Cvele Cvele
Greenhorn

Joined: Feb 25, 2009
Posts: 1
Hi,
We have one JSF actionListener with just one, long-runnig statement (for example, Oracle stored proc call).
Now, we want to provide our user with ability to cancel this actionListener, by clicking to another, 'Cancel' command Button

In general, wonder if this possible at all (so, to cancel some Java server side method) and if yes, how to do this , if this method actually a stored proc call ?

My idea (for now) is :

* To use that actionListener in order to start new Java Thread (which calls stored proc).

After that, the same actionListener saves reference to the PreparedStatement (whics executes updates) in order to call PreparedStatement.cancel() on later) AND finishes its works (along with JSF lifecycle), but stored proc continues execution i its own Thread, now outside of JSF lifecycle.

In this scenario, one question comes to mind :
Stored proc changes some database data, which needs to be displayed on the JSF page. How to detect that stored proc's thread finished its execution (or that exception happens), in order to refresh User interface with a new data ?

However (forget for stored proc for now), the main question is : how to cancel long-running JSF actionListener ? What needs to be done on the user interface side, and on the server side ?

Thanks in advance
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Poll the server for changes and inform the client accordingly.
Ajax is extremely useful in this to let it happen asynchronously.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16054
    
  21

You shouldn't HAVE long-running action listeners. In fact, be it JSF, Struts, or even simple JSPs, long-running actions should not be attached to the request/reply processors.

Even having the processor spawn a thread may lead to problems. A cleaner solution is to set up an independent engine and have the processors queue up requests to the engine. I often use what I call a "null servlet" for this. A null servlet is simply a servlet that has an init() method that sets up the engine thread(s) and request queue(s), but doesn't have a doGet/doPost or other request dispatcher. You normally configure web.xml to auto-start this servlet, since there won't be any web requests coming in to launch it.

Because JSF is based on HTTP and HTTP is solely request/response, with no way to post unrequested responses, you have to have the client poll the engine for status. Traditionally, that was done with a timed refresh HTML meta-tag, but if you're using an AJAX framework like RichFaces, there are other more JSF-friendly ways to do the polling as well.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to cancell long-runnig actionListener /stored proc. call/