Hello all,
I'm posting this for a few reasons.
1) To publicly acknowledge the help that I got from Ken Lalonde (Again,
many thanks).
2) To summarize everything so that someone else can find this solution
in the archives.
3) See if anyone can find a problem/issue that I have not yet
considered.
Building on Ken's code that can be found here,
http://sourceforge.net/mailarchive/forum.php?thread_id=3561201&forum_id=3505
Firstly, all of my pages now include a unique identifier that is
contained within a hidden field on the page. The identifier is a
combination of the time and a random number (as per Ken's code).
In my Controller class (which makes decisions about input and forwards
request to other pages), immediately after the base class awake method I
check to see if this page can be processed. This check consists of 2
parts. In the first part I check a dictionary that is stored in the
session. The keys to this dictionary are the unique page identifiers. If
the identifier is found in the dictionary, then the page can NOT be
processed. This is the same check that is done within Ken's code. If the
identifier is not found then we check the session to see if a
'processing' flag has been set. If the flag exists, then we can NOT
process the page since we are currently processing a different request.
If the above method indicates that we can process the page, then we set
a processing flag and start the various calculations. These calculations
can take less than a second or up to a minute (slow machine and slow
database connection). As the request finishes off control is forwarded
to another page (goodInputPage, badInputPage, needMoreInputPage, etc).
The forwarded page writes out all of the information that it recovered
from the database. Then, it it's respond method, it removes the
processing flag (if it exists) and sets the 'lastPageVisited' session
variable.
If the user submits a request that can not be processed, then the
writeContent of the controller class is called. This is the only time
that this code is called. It will display a page telling the user that
the request is still being processed and supply them with a method to
submit the page. if they submit the page will the processing flag is
still set they will be directed back to the 'wait' page.
Eventually the processing flag will be removed and the user will submit
the page. This will allow the controller class to make some decisions
based on the input it was given. However, at this point, the page will
have no input. There will be the submit button, but that has been
stripped out of the request in the method that checks if the page can be
processed. If the page is submitted, but there are no other fields in
the request, then the last page that was displayed is re-displayed. As
noted above, the last displayed page is stored in the session. Due to
the hierarchy of classes, the controller class never sets itself as a
last displayed page.
If I have all this figured out then the original response is being
processed and will eventually update the session data with whatever is
appropriate and the user can sit in the 'canProcess' loop for as long as
necessary for the original response to complete.
If anyone can see a problem with this, please say something. It seems to
be working right now, but I don't like leaving bugs lying around.
David London
|