cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject Possible bug: flow loosing top level variables?
Date Sun, 16 May 2004 18:10:09 GMT
I'm posting this to dev because my case is connected with some bug in flow.
The problem I'm describing does not occur in cocoon 2004-04-05 (or 
something around). Cocoon 2004-04-23 (or something around :) - I still 
do not have a way to track exact cocoon snapshot date) already breaks my 
project, current HEAD also.

Thing is:
I have all my web application requests redirected to main() function (I 
have to quote this as my Mozilla Thunderbird has "Paste without 
formatting" disabled .. ):

> var user = null;
> 
> function main( action ) {
>     cocoon.response.setHeader( "Expires", "-1" );
>   cocoon.response.setHeader( "Cache-Control", "no-cache" );
>   cocoon.response.setHeader( "Pragma", "no-cache" );
>  
>    if ( user == null ) {
>       loginInternal();
>    }
>   invoke( action );
> }
> 
> function invoke( action ) {
>     func = this[ action ];
>     if ( func != undefined )    
>         func.apply( this );
>     else 
>       cocoon.sendPage( action, {} );
> }
> 
> function loginInternal() {
>  var form = new Form( "forms/login-def.xml" );
>   var model = form.getModel();
>    form.validator = loginValidator;
>    form.showForm( "form/login", {} );
> }
> 
> function loginValidator( form ) { 
>    var query = nTerApi.session.createQuery( "from User where name = :name and password
= :password" );
>     query.setString( "name", form.getWidget( "username" ).getValue() );
>     query.setString( "password", form.getWidget( "password" ).getValue() );
>     
>    var list = query.list();
>    if ( list.size() == 0 ) {   
>        form.getWidget( "messages" ).addMessage( "B-ŕdny u¬ytkownik lub has-o!" );
>      return false;
>   }
> 
>  user = list.get( 0 );   
>    cocoon.session.setAttribute( "user", user );
>    return true;
> }
> 
> function login() {
>  cocoon.redirectTo( "/nTer/userDetails.do" );
> }
> 
> function logout() {
>     user = null;
>    cocoon.session.invalidate();
>    cocoon.redirectTo( "/nTer/userDetails.do" );
> } 

As you see if top level variable "user" is not set loginInternal is 
being invoked. You are presented with login screen that has some simple 
menu. Form validator sets the variable so next calls should not show 
login form (I have made the appropriate changes in forms for cocoon HEAD 
version, cocoon 2004-04-23 still uses old api).

After you login you are presented with an enhanced menu and default 
application screen. The enhaced menu is only shown when 
cocoon.session.user is set.

Now you click anything on the menu. And you get the login screen back - 
but WITH the enhanced menu. So you did not loose your session 
(cocoon.session.user is still there) but you lost flow top level 
variable "user". You enter login data again and from now on everything 
works as expected - you do not loose flow top level variable again.

This is my sitemap excerpt (if that helps anything):
> <map:resource name="resume-continuation">
>     <map:act type="set-header">
>         <map:parameter name="Expires" value="-1"/>
>         <map:parameter name="Cache-Control" value="no-cache"/>
>         <map:parameter name="Pragma" value="no-cache"/>
>         <map:call continuation="{../continuation-id}"/>
>     </map:act>
> </map:resource>
> <snip/>
> <map:match type="regexp" pattern="(.*/)?(.*)\.cont(inue)?">
>     <map:call resource="resume-continuation">
>         <map:parameter name="continuation-id" value="{2}"/>
>     </map:call>
> </map:match>
> <map:match pattern="*.do">
>     <map:match type="request-parameter" pattern="continuation-id">
>         <map:call resource="resume-continuation">
>             <map:parameter name="continuation-id" value="{1}"/>
>         </map:call>
>     </map:match>
>     <map:call function="main">
>         <map:parameter name="action" value="{1}"/>
>     </map:call>
> </map:match>
> <map:match pattern="**/*">
>     <map:call function="main">
>         <map:parameter name="action" value="{0}"/>
>     </map:call>
> </map:match>

WDYT?
	Leszek Gawron

Mime
View raw message