cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Franziska Witzani" <franziska.witz...@e-tecture.com>
Subject AW: Continuations: Snapshot or Pointers?
Date Fri, 13 Apr 2007 11:43:37 GMT
Hi Jason, hi Joerg!

cocoon.createPageLocal() was exactly what I've been looking for. Thanks a lot! 

@Joerg: what you said about the difference between values of variables and references to objects
is true for saving them in the PageLocal-Object.
In Continuations Flowscript-Variables seem to be only referenced as well.

This proves this little sample:

function main()
{
    var random = Math.round( Math.random() * 9 ) + 1;
    var hint = "Noch keine Eingaben.";
    var guesses = 0;

    while(true)
    {
        cocoon.sendPageAndWait("guess.jxt", {"random" : random, "hint" : hint, "guesses" :
guesses});
        var guess = parseInt(cocoon.request.get("guess"));
        guesses++;
         
        if(guess>random)
        {
            hint = "Nö, niedriger!";
        }
        else if(guess<random)
        {
            hint = "Nö, höher!";
        }
        else
        {
            break;
        }
    }
    
    cocoon.sendPage("success.jxt", {"guess" : guess, "random" : random, "guesses" : guesses});
}


The Variable "guesses" works as a counter and is not set back if you're navigating backwards
with Continuations.
But using the PageLocal-object solves my problem.


And I have another question:
How can I serialize the contents of a CForms-Datamodel which you get from formObject.getModel()
Into the PageLocal-Object?
I mean, dynamically, without knowing the ids of the widgets,
Something like:

[pseudocode]
...
dataModel = formObject.getModel();
for (var key in dataModel)
{
	pageLocalObj.key = dataModel.key;
}
...

Or could you tell me the path to the sources, please, where I could look for implemented methods
or something? I couldn't find it...


Regards,
Franzi





-----Ursprüngliche Nachricht-----
Von: Jason Johnston [mailto:cocoon@lojjic.net] 
Gesendet: Donnerstag, 12. April 2007 22:46
An: users@cocoon.apache.org
Betreff: Re: Continuations: Snapshot or Pointers?

On Thu, 12 Apr 2007 21:41:06 +0200, Joerg Heinicke <joerg.heinicke@gmx.de> wrote:
> On 12.04.2007 16:02, Franziska Witzani wrote:
> 
>> According to the documentation I have (especially the book of Stephan
>> Niedermeier), a continuation is a snapshot of the variables of the
>> flowscript (by the time the continuation is created/saved) and a pointer
> to
>> the point of the flowscript which actually is being executed.
>>
>> I experienced, that this is not exactly the case. What seems to be saved
>> within the continuation is not a snapshot of the variables, but only
>> pointers to their values.
>>
>> (For example, if you have a counter, which is incremented after each
>> "sendPageAndWait()" it will not be set back if you go back with
>> continuations, but always hold the highest value.)
> 
> They are indeed pointers, not snapshots. But this is only true for
> objects. AFAIK there is no way to point to a primitive type, they are
> always passed by value, not by reference. This means a simple counter
> should indeed be resetted going back to an old continuation. But
> somebody else can correct me on this. Torsten?
>
>> Is there a way to change that by configuring something, or will I have
> to
>> change the Cocoon-source code or find another way around it?
> 
> No, there is no way to configure it. Actually I wonder how this should
> be possible at all. How do you want to store and restore an object? I
> can only imagine serializing and deserializing objects, but I'm not
> aware of such an implementation. It would probably quite nice as you
> don't need to care about any object state, but it's limiting to a
> certain extend (to Serializable actually) and maybe not well performing.

I've never tried using it, but if I understand the Flowscript documentation correctly, cocoon.createPageLocal()
will create an object that restores its state at the time the continuation was created.  Franziska
this may fill your need.

--Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message