Roberto Pierpaoli wrote:
Details:
* Cocoon 2.1.7 standalone
* JDK 1.5.0_03
* Windows 2000 SP4
I have made a small example to test the use of continuations, it is made
of a simple counter that is incremented each time the user presses the
"count" button, then, when the "stop" button is pressed, the result
page, containing the final value of the counter, is sent.
On the basis of what I have understood about continuations, I expected
that, pressing the "BACK" button of the browser, old continuations
should be restored and local variables should be restored with them, for
example: I press "count" five times, so the value is now 5 (assuming the
initial value equal to zero), now I press the back button two times (I
expect the value to be restored to three) and in the end I press the
"stop" button ... but the result shown is still 5, and not 3 as expected!
What's wrong with my aproach?
The official documentation says:
/"With continuations in the language, you can essentially store the
continuation of |sendPageAndWait()| (think of all the stack trace, and
the program counter), put it in a global hash table associated with an
id. The id is then encoded in the |response.xml| page as an URL. When
the user clicks on that URL, on the server side the associated
continuation is resumed. Resuming the processing happens as if nothing
was stopped, you get all the stack trace back, and all the local
variables.//
So instead of using beans to store things in session, you use normal
variables in a program. Since each user has its own version of the
program, all the local variables in the program are separate between users.
With this approach clicking the Back button in the browser is no longer
a hassle to deal with for you as a server-side programmer. They will
simply refer to past continuations objects, which have their own state
of the local variables./
/Since continuations are objects, you can also store them in a database,
for really long-lived session, just like you do with session beans."/
Any help or suggestion is very appriciated!
What you explained is correct, the docs are not very clear about this. All
continuations of *one continuations tree* share all local variables. Global
variables are shared by all continuation trees.
If you want to bahaviour that a variable is bound to a continuation (and not the
tree it belongs to) you have to create a PageLocal variable:
var pageLocal = cocoon.createPageLocal();
pageLocal.counter = ...
HTH
--
Reinhard Pötz Independent Consultant, Trainer & (IT)-Coach
{Software Engineering, Open Source, Web Applications, Apache Cocoon}
web(log): http://www.poetz.cc
--------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]