the reason why Dan said you need to be carefull with creating delegates in your 
command's constructor is because the creation of remote services sometimes 
seems to be a very expensive operation, it might run over multiple frames so 
you might not be able to rely on defining your remote services before defining 
your front controller in one MXML file, since this will be compiled to one 
ActionScript block, which runs in one frame. 

So, 

<!-- the ServiceLocator where we specify the remote services -->
<business:Services id="services" />
        
<!-- the FrontController, containing Commands specific to this appliation -->
<control:Controller id="controller" />

can yield to the problem that remote services are not defined when the 
constructors of the commands in your FrontController run. This is why we 
initialise business delegates in each command's execute method. Commands are 
stateless anyway, and creating instance variables currently can have side 
effects in this version of Cairngorm. 


Best,
Alex

-- 
Alex Uhlmann 
Software Engineer 
iteration::two



-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] Behalf Of flexcoding
Sent: 31 August 2005 22:19
To: [email protected]
Subject: [flexcoders] Re: CAIRNGORM 0.99 QUESTION


Hi,

Thanks for the reply. You must be a very experienced programmer 
because you just looked at the suggestion and found the problem it 
will create two steps down. I have experienced the same problem that 
you mentioned below if I use recommended <mx:Application> tag 
instead of <cairngorm:CairngormApplication> tag, but I had to spend 
considerable time to nail down the cause, which I believe, and like 
you said, is that the ServiceLocator.getInstance() is failing 
because it hasn't been initialized yet.

1. How can I ensure that my services are created before my front 
controller in the Index?

2. Does this approach of creating delegates in Command Constructor 
has any advantage/disadvantage?

Thanks & Regards,

Rohit Chhabra.

--- In [email protected], "Daniel Harfleet" 
<[EMAIL PROTECTED]> wrote:
> Hi,
> 
> you would need to be carefull, because the command instances are
> created once only at creation of the FrontController. By creating a
> delegate instance, you are using the ServiceLocator to look up the
> remote object, however, if your service locator hasn't been
> initialized yet, you may get  a no service found error. So make 
sure
> your services are created before you front controller if you are 
going
> to take this approach.
> 
> 
> 
> --- In [email protected], "flexcoding" <[EMAIL PROTECTED]> 
wrote:
> > Is it OK to have a constructor in the Command classes and have 
> > delegate initialized there rather than doing it in every time 
> > execute method is called?
> > 
> > So Could the code of LoginCommand of sample code that came with 
> > CAIRNGORM 0.99 be changed to:
> > 
> > class org.nevis.cairngorm.samples.login.commands.LoginCommand 
> > implements Command, Responder
> > {
> >    private var delegate: CustomerDelegate;
> > 
> >    public function LoginCommand ()
> >    {
> >       delegate = new CustomerDelegate( this );
> >    }
> > 
> >    public function execute( event:Event ) : Void
> >    {
> >       var loginVO : LoginVO = LoginVO( event.data );
> >       delegate.login( loginVO );
> >    }
> > 
> > //---------------------------------------------------------------
----
> > ------
> > 
> >    public function onResult( event : Object ) : Void
> >    {      
> >       ModelLocator.workflowState = 
> > ModelLocator.VIEWING_LOGGED_IN_SCREEN;
> >       
> >       var loginDate : Date = Date( event.result );   
> >       ModelLocator.loginDate = loginDate;
> >    }
> > 
> > //---------------------------------------------------------------
----
> > ------
> > 
> >    public function onFault( event : Object ) : Void
> >    {
> >       ModelLocator.statusMessage = "Your username or password 
was 
> > wrong, please try again.";
> >    }
> > }
> > 
> > from
> > 
> > /*
> > 
> > Copyright 2005 iteration::two Ltd
> > 
> > Licensed under the Apache License, Version 2.0 (the "License");
> > you may not use this file except in compliance with the License.
> > You may obtain a copy of the License at
> > 
> >     http://www.apache.org/licenses/LICENSE-2.0
> > 
> > Unless required by applicable law or agreed to in writing, 
software
> > distributed under the License is distributed on an "AS IS" BASIS,
> > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
> > implied.
> > See the License for the specific language governing permissions 
and
> > limitations under the License.
> > 
> > @ignore
> > */
> > import org.nevis.cairngorm.business.Responder;
> > import org.nevis.cairngorm.commands.Command;
> > import org.nevis.cairngorm.control.Event;
> > import 
org.nevis.cairngorm.samples.login.business.CustomerDelegate;
> > import org.nevis.cairngorm.samples.login.vo.LoginVO;
> > import org.nevis.cairngorm.samples.login.model.ModelLocator;
> > 
> > /**
> >  * @version      $Revision: 1.4 $
> >  */
> > class org.nevis.cairngorm.samples.login.commands.LoginCommand 
> > implements Command, Responder
> > {
> > 
> >    public function execute( event:Event ) : Void
> >    {
> >       var delegate: CustomerDelegate = new CustomerDelegate( 
> > this );     
> >       var loginVO : LoginVO = LoginVO( event.data );
> >       delegate.login( loginVO );
> >    }
> > 
> > //---------------------------------------------------------------
----
> > ------
> > 
> >    public function onResult( event : Object ) : Void
> >    {      
> >       ModelLocator.workflowState = 
> > ModelLocator.VIEWING_LOGGED_IN_SCREEN;
> >       
> >       var loginDate : Date = Date( event.result );   
> >       ModelLocator.loginDate = loginDate;
> >    }
> > 
> > //---------------------------------------------------------------
----
> > ------
> > 
> >    public function onFault( event : Object ) : Void
> >    {
> >       ModelLocator.statusMessage = "Your username or password 
was 
> > wrong, please try again.";
> >    }
> > }





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 




YAHOO! GROUPS LINKS 

 Visit your group "flexcoders" on the web.
  
 To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]
  
 Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to