Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Mediator Problem  (Read 10801 times)
isragaytan
Full Member
***
Posts: 22


View Profile Email
« on: May 12, 2009, 12:43:43 »

Hello everyone!

I have a little complication in my Mediator.

Here is the scenario:

I am working with the pureMVC MultiCore.
At startup i prepare the proper proxy and views  for a data retrieval. This works fine
since all the calls are executed correctly. In the mediator i have a reference to my view
component and my proxy so i handle a notification like this:

 case ApplicationFacade.ObtenEstadosCiviles_finished:
                ApplicationFacade.getInstance(APPNAME).catalogosResult.ObtenEstadosCivilesResult = notification.getBody() as Array;
                  
               datosCompSolicitud.DatosPersonas.myCBEstadoCivil.data="Gc04IdEstadoCivil";   
               datosCompSolicitud.DatosPersonas.myCBEstadoCivil.labelField = "Gc04EstadoCivil";               
               datosCompSolicitud.DatosPersonas.myCBEstadoCivil.dataProvider=listProxy.getData().ObtenEstadosCivilesResult;
              
              
                 break;   

this works fine in the proper comboBox!

First question here its..

Why my notification.getBody() dont have anything? since i send in the proxy the proper notification like this..

private virtual function ObtenEstadosCivilesHandler(event:ResultEvent):void
        {                   
           //ObtenEstadosCiviles
           //Alert.show("Obteniendo resultados en el proxy");
           catalogos.ObtenEstadosCivilesResult=event.result as Array;
           setData(catalogos);
            sendNotification( ApplicationFacade.ObtenEstadosCiviles_finished, catalogos.ObtenEstadosCivilesResult );
       
           
        }

Second question and here is my headache

When i assign to another notification interest the data in the first combo dissapears...its important to say that i debug the listProxy and i have all the necesary data!!! it has the correct data

so..my code is

case ApplicationFacade.ObtenPaises_finished:
              
               ApplicationFacade.getInstance(APPNAME).catalogosResult.ObtenPaisesResult = notification.getBody() as Array;
              
              
               datosCompSolicitud.DatosPersonas.myCBPaisNacio.data="Gc06IdPais";
               datosCompSolicitud.DatosPersonas.myCBPaisNacio.labelField="Gc06Pais";
            datosCompSolicitud.DatosPersonas.myCBPaisNacio.dataProvider=listProxy.getData().ObtenPaisesResult;
              
                 break; 

I debug and the proxy has all the data.. I dont know what i am missing, i checked all the name instances everything necesary and i dont find the problem

Thanks in advance..
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 12, 2009, 04:59:03 »

The one useful thing I can tell you is that you don't need to get the facade instance; all mediators, proxies and commands already have a reference to your facade.

So instead of

:
ApplicationFacade.getInstance(APPNAME).
just do

:
facade.
So my first question is what are you doing here:
:
ApplicationFacade.getInstance(APPNAME).catalogosResult.ObtenEstadosCivilesResult = notification.getBody() as Array;
It looks like you're setting the result on your facade. That doesn't make sense. You should be getting it into a local variable to set on the view component.

Second question is in your proxy, you have:
:
catalogos.ObtenEstadosCivilesResult=event.result as Array;
Is catalogos defined somewhere else? Is catalogos perhaps an implicit getter that looks like:

private function get catalogos():Array
{
    return data as Array;
}

If so, is it possible that catalogos is null when you try to set its ObtenEstadosCivilesResult property? Have you set a breakpoint in the Flex Builder debugger on the sendNotification like and checked out catalogos.ObtenEstadosCivilesResult in the variables view at that point? Have you set a breakpoint right on the first line of the ObtenEstadosCivilesHandler method and investigated the event property?

-=Cliff>
Logged
isragaytan
Full Member
***
Posts: 22


View Profile Email
« Reply #2 on: May 13, 2009, 06:19:56 »

Thanks Cliff i resolved the problem.! ;D

The problem was a reference in catalogs. Thats done!!!

Now i got a question about register views...

When i initialize the application i do it with the proper command for
example ViewPrepCommand like this..:

override public function execute(notification:INotification):void{
         
         var app:cdiintegra=notification.getBody() as cdiintegra;
         
         //Registro el mediador
         facade.registerMediator(new SolicitudSocioMediator(app.solicitudSocio));
         
}

If i have more views inside solicitudSocio component with the proper id.. do i have also register those views?? and the proper mediators???

If the answer is yes how can i do that?

something like this?...

override public function execute(notification:INotification):void{
         
         var app:cdiintegra=notification.getBody() as cdiintegra;
         
         //Registro el mediador
         facade.registerMediator(new SolicitudSocioMediator(app.solicitudSocio));

                   facade.registerMediator(new SolicitudSocioMediator(app.solicitudSocio.DatosSolicitudSocio));
         
}

Thanks PUREMVC  ;D



Logged
Bill_BSB
Jr. Member
**
Posts: 13


View Profile Email
« Reply #3 on: May 13, 2009, 07:49:00 »

Hey Isra!

Your code is correct!

You should checkout the source files of the demos. They cover pretty much of all those questions.

=)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: May 14, 2009, 05:25:48 »

You should probably make the mediator for the app actually mediate the app and not a child of it.

:
override public function execute( notification:INotification ):void
{
         
         var app:cdiintegra=notification.getBody() as cdiintegra;
         
         //Registro el mediador
         facade.registerMediator( new ApplicationMediator( app ) );
         
}

And if you have children of the app that need mediators, you can register them in the ApplicationMediator.

:
override public function onRegister():void
{
         //Registro el mediador
         facade.registerMediator( new SolicitudSocioMediator( app.solicitudSocio ) );
}

private function get app():cdiintegra
{
   return viewComponent as cdiintegra;
}

And if those children have children that need mediators...

:
override public function onRegister():void
{
         //Registro el mediador
         facade.registerMediator( new DatosSolicitudSocioMediator( datosSolicitudSocio.DatosSolicitudSocio ) );
}

private function get datosSolicitudSocio():DatosSolicitudSocio
{
   return viewComponent as DatosSolicitudSocio;
}

This way the Mediator whose job it is to know the app or component in question is the one in charge of registering its children's mediators.
 
-=Cliff>
Logged
isragaytan
Full Member
***
Posts: 22


View Profile Email
« Reply #5 on: May 14, 2009, 07:14:25 »

Thanks again Cliff!!!..

Yesterday i saw a very nice example about diferred instanciation. (Slacker) since i have a tab in my main window..... This solved a lot of questions about the application. Also i saw how you can handle popups and its a little bit the same thing. I have to register the mediators! "on the fly...


Thanks a lot Cliff :D ...


Logged
Pages: [1]
Print