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: Proxy VO Getters  (Read 13950 times)
Vander
Full Member
***
Posts: 32


View Profile Email
« on: April 16, 2008, 03:01:07 »

Hello everyone o/

Im Vander from Brazil, and im joining pmvc/flex/amfphp paradigm.
Im so happy... and starting to became less scared with all new stuff.
Ive used to program in flash/as2.. and i developed some RIA´s.. for some companies, including a little big one.
Yes ive stucked with all that rotten workflow hehe.
Ive developed a minimal application using PureMVC concept... and VO... it worked :)
consists of a button, that when click on it... it adds ++ to a uint.. and a label display it...
its something like that:

pseudo

view... import vo bindable... binding label.text
mediator... command addnumber... proxy... function addnumber etc
then notification... mediator boom view... ok works fine :)

but im having a great doubt that pulled me to became a forum member...

for example... im initializing the vo in the view...

[Bindable]
public var valor:Valor=new Valor(0);

0 is the initial value.. no problem with that... automatically the label.text becames 0, as expected...

my problem is... i cannot manage to make a getter for the actual value.. in the proxy
ive tried all but i dont understand how...

i guess that the problem is connected with a point of puremvc that i simply cannot understand... THE PROXY CONSTRUCTOR.
and/or the SUPER second argument.

Thanks... everyone, thanks Cliff.
Logged
Rhysyngsun
Courseware Beta
Sr. Member
***
Posts: 51

Nathan Levesque

 - rhysyngsun@gmail.com  - rhysyngsun
View Profile WWW Email
« Reply #1 on: April 16, 2008, 09:49:06 »

The second parameter in the Proxy class constructor is for passing your data to the data variable. This depends highly on your needs. If you've only keeping track of one data object, you can just pass that along, otherwise you may want to consider something like an ArrayCollection for storing a whole dataset. You then typically define a getter to return the data variable cast  to the appropriate data type.

So in your case (if I understand correctly that you're only keeping track of one), you would be doing:

:
public function ValorProxy()
{
super(NAME, new Valor(0))
}

...


public function get valor():Valor
{
return data as Valor;
}

Then in your mediator, assign the value of the valor getter to the value variable on your view instead of instantiating it in your view. Now your view references the data on the Proxy and the Proxy manages the data.
Logged

Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #2 on: April 17, 2008, 05:44:10 »

Okay.. maybe i must tell you that im using bindable on view
something like this:

import vo...

[Bindable]
public var valor:Valor=new Valor(0);

and im trying to use getter too, just for test..
because i want to know how use it when i want..

thanks for the help, but you can help me more? :)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: April 18, 2008, 07:38:59 »

You don't want to use the getter on the proxy from within a view component. View components should know nothing of the PureMVC app. That's not to say they can't know the VO, as Nathan showed above. And it's ok for you to bind within that component to this variable that holds the VO. You just want the VO to be placed there by the Mediator for the View Component.

-=Cliff>
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #4 on: April 18, 2008, 07:47:58 »

im not using the getter on the view! :)

im trying to trace a getter in the command.. just to know how to retrieve some value from the value object, through the proxy...

i feel that im still little confused about VO and PROXY relationship...
something between the getter... and how to access the imported VO in proxy to retrieve the data.. since its initializaed on the view as you saw in the bindable...(new Valor(0))...

take a look my proxy

package com.drm.Login.model
{
   import com.drm.Login.ApplicationFacade;
   import com.drm.Login.model.vo.Valor;
   
   import org.puremvc.as3.interfaces.*;
   import org.puremvc.as3.patterns.proxy.Proxy;
         
   /*
   testando um proxy
    */
   public class TesteProxy extends Proxy implements IProxy
   {
      
      public static const NAME:String ="TesteProxy";
         
      public function TesteProxy()
      {
         //the vo is initialized on the view with the 0 value...
         //is bindable... so it automatically update de label.text
         //its work fine
         super (NAME);

      }

      public function acrescentaNumero(valor:Valor):void{
         //the command pass to here.. the valor object..
         //then adds a number to it... hmm i really updating the VO?
         //i guess that yes its..
         //it just works.
      valor.valor++;
      sendNotification(ApplicationFacade.ACRESCENTOU_NUMERO,valor);
      
      }
      public function get valor( ) : Valor {
         //i cant figure out how to do this...
         trace (data);  //but whats data?? hehehe
                     //i know that must be on the proxy constructor
                     //but... im not initializing in the proxy!
                     //how can i access it?
                     //im little confused.
                     //can help me please? :)
         return data as Valor;

      }
         
   }

}
Logged
Rhysyngsun
Courseware Beta
Sr. Member
***
Posts: 51

Nathan Levesque

 - rhysyngsun@gmail.com  - rhysyngsun
View Profile WWW Email
« Reply #5 on: April 18, 2008, 08:19:44 »

The second parameter in super() is the value to set data as. So in this case you're probably going to get a null reference error. You'll want to change to this, so that data gets initialized:

super( NAME, new Valor() );

You don't want to initialize on the view, because the view should not be manipulating data, only displaying it.
Logged

Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #6 on: April 18, 2008, 08:26:28 »

Hmm.. so how i let my view now?... actually its this way:

   <mx:Script>
   
      <![CDATA[
      
         import com.drm.Login.ApplicationFacade;
         import com.drm.Login.model.vo.Valor;
         
         public static const ACRESCENTA_NUMERO: String = "acrescentaNumero";
         public static const ACRESCENTOU_NUMERO: String = "acrescentouNumero";
                  
         [Bindable]
         public var valor:Valor=new Valor(0);
                              
         public function botaoSomar():void{
            dispatchEvent (new Event(ACRESCENTA_NUMERO));            
         }   
         
      ]]>
   </mx:Script>
   
   
   <mx:HBox>
   <mx:Button id="somarBtn" label="Soma" click="botaoSomar()"/>
   <mx:Label id="numLabel" text="{valor.valor}"/>
   </mx:HBox>   

MANY THANKS AND SORRY FOR DISTURBING...
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #7 on: April 18, 2008, 08:30:43 »

okay, im posting my VO too...

   [RemoteClass(alias="com.drm.Login.model.vo.Valor")]
   
   
   [Bindable]
   public class Valor
   {

      public var valor : uint;
      
      public function Valor( valor : uint )
      {
         this.valor = valor;
      }
   }


note, that it receives the initial argument
my intention is that its initialized with value 0
new Valor(0)
so this way the label.text (bindable) start with 0...

im doing wrong approach?

thanks rhysyng and hall
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #8 on: April 18, 2008, 09:40:17 »

Sounds fine though the Class name and the member name being the same will be strange if you do:

import ...Valor;
var valor:Valor = new Valor(0);
txtValor.text = valor.valor;


-=Cliff>
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #9 on: April 18, 2008, 11:38:12 »

ive changed the member 'valor' to 'valor1' inside 'valor' object
but... anyway...

i still confused...
im initializing the object in the view... and in the proxy...

...(new Value(0))...

if i trace the getter in a command
or even inside the getter
ive got "object object"
but when i trace the .valor
or return of the getter in command
or even of the 'data' in getter
i get 0

it seems that the vo isnt updating

sorry all inconvenience but its the only thing
that im get chained to start to work in puremvc
actually...
:)
thanks cliff


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



View Profile WWW Email
« Reply #10 on: April 18, 2008, 11:46:56 »

Rather than initialize the VO at the View, perhaps do that in the Proxy, and have the mediator for this view component set the VO retrieved from the Proxy.

-=Cliff>
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #11 on: April 18, 2008, 12:40:18 »

WOW! think that now all worked!! traced in both places (command and proxy getter) :)

thanks cliff...

and i can understand by all this stuff. that the VO must be initialized just one time!, in one place.. im correct? :)

so...

on the view...

ive let the bindable this way now (without initialize)


        [Bindable]
        public var valor:Valor;


and in the mediator
im getting in the constructor...
am i right? :)
or i should put in another place?
like an event onComplete
hmm i think if i want initialize a series of controls
i can put it in a command right?
thanks.. and correct me if i need :)


        public function MainViewMediator( viewComponent:Object )
        {
            // pass the viewComponent to the superclass where
            // it will be stored in the inherited viewComponent property
            super( NAME, viewComponent );
         
         // retrieve the proxies
         testeProxy = TesteProxy (facade.retrieveProxy( TesteProxy.NAME ));
         
         mainView.addEventListener( MainView.ACRESCENTA_NUMERO, soma );

         mainView.valor=testeProxy.valor;
      }
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #12 on: April 18, 2008, 01:15:57 »

okay.. im thinking that i can initialize the view either by vo values... and
values that i want (direct initializing)
depends each case... :)
Logged
Pages: [1]
Print