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

Show Posts

| * |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / Architecture / Caching the results of db query? on: December 29, 2008, 03:22:22
Hi,

How can I cache the results of a query.  I am generating a list of states (Alabama, Alaska, Arkansas, etc, etc) for various combo boxes in my application.  I want to get a list of the states once on startup, but have a way for the views that need the combobox to all look at once location for the data provider. 

How and where would I do this? As of now I have this, but it doesn't cache the results which is what I'd like

----
StatesCommand.as

var geographyProxy:GeographyProxy = facade.retrieveProxy( GeographyProxy.NAME ) as GeographyProxy;
geographyProxy.getStates();

GeographyProxy.as

public function getStates():void {
  remoteDelegate.getStates();
}

public function result( event:Object ):void      {   
    switch ( event.token.message.operation )   {
   case "getStates":
   var ac_result:ArrayCollection = event.result as ArrayCollection;
   var obj:Object = new Object();
             obj.state_code = '';
   obj.state_name = 'Choose a State';
   ac_result.addItemAt(obj, 0);
   sendNotification( STATES_LOADED, ac_result );
   break;
----

I am unsure how I can cache this as well as is this even the right way to setup my command and my proxy.  It also leads to a more frustrating problem that when this notification "STATES_LOADED" is distributed, some of the view components that need to hear it are not created yet which results in me having to make another db call for the same data when one of the other views doesn't exist.

Hope my post makes sense.

-Westside


2  Announcements and General Discussion / Architecture / Question on Code Reuse on: December 18, 2008, 04:41:55
Hi,

I have a question on how I can correctly wire things up to get the most reuse out of some code I wrote.  My code works fine as it is but I am having trouble finding how how to reuse this code when say another combo box in a different view needs to show the same list of U.S. states.   So let's say I have "View A" and "View B" for purposes of this example.  "View A" and "View B" are two different views shown at two different times

I have the following code:

LoadStatesCommand.as

public class LoadStatesCommand extends SimpleCommand implements ICommand  {
      
    override public function execute(note:INotification):void      {
      var geographyProxy:GeographyProxy = facade.retrieveProxy( GeographyProxy.NAME ) as GeographyProxy;
      geographyProxy.loadUSStates();
   }
      
} // close class

GeographyProxy.as

public function loadUSStates():void {
   remoteDelegate.getUSStates();
}

public function result( event:Object ):void      {   
    switch ( event.token.message.operation )   {
       case "getUSStates":
         var ac_result:ArrayCollection = event.result as ArrayCollection;
         var obj:Object = new Object();
         obj.state_code = '';
         obj.state_name = 'Choose a State';
         ac_result.addItemAt(obj, 0);
         sendNotification( STATES_LOADED, ac_result );
       break;
  }
}

So the above works, and after the data comes back from my remote service I send a notification out (STATES_LOADED) and the mediator for "View A" has an interest in this notification and when it hears it, it handles it by taking the array collection and binding it to my comboBox.  I got this part working fine.

But now say the the user is looking at only "View B", it also has a comboBox that needs populating, how can I use the same code to populate it?  I can't send out the same notification otherwise "View A" will hear it which I don't want.

Hope I am making sense...

Thanks,

-Westside
3  Announcements and General Discussion / Architecture / Event gets Dispatched, but Mediator Not recognizing the Event?? on: December 10, 2008, 10:32:17
Hi,

I have an event that gets dispatched from a "view" within a ViewStack upon creationComplete.  As part of my troubleshooting process I put a breakpoint to ensure that the event was in fact being dispatched and that works.  This mediator is mediating for a ViewStack.  When the first view in the ViewStack calls its "creationComplete" method I dispatch my event.

The problem is the callback function in the Mediator "never" gets called and I can't figure out why.  Any help highly appreciated.

In: MainDisplay.mxml

public static const GET_STATES:String = 'getStates';

private function loadStates(event:Event):void  {
     dispatchEvent( new Event( GET_STATES,true ) );
}

 <mx:ViewStack id="myStack"
     selectedIndex="{currentViewSelector}"
       creationPolicy="auto" 
       width="100%" height="100%"
    >
       
 <view:SplashView id="splashPage" showEffect="{fade_HomePage}" hideEffect="{zoom_HomePage}" creationComplete="loadStates(event)"/>

</mx:ViewStack>

In: MainDisplayMediator.as

override public function onRegister():void  {
  mainDisplay.addEventListener( MainDisplay.GET_STATES, cbLoadStates );
}

private function cbLoadStates ( event:Event ):void  {
    Alert.show('If this shows, then the call back function works');
   sendNotification( ApplicationFacade.LOAD_STATES );
         
}
4  Announcements and General Discussion / Architecture / One Mediator multiple Views? on: December 03, 2008, 04:48:46
Hi,

Can someone provide a coding example of how I can have one mediator mediate two views?  So far I have this code (below) which works for one mediator and one view, but it seems like a lot of extra work to have one mediator for every view component so I would like my "mediator" to mediate for two views for example.

Here is my existing code:

public static const NAME:String = 'SearchMediator';

public function SearchMediator( viewComponent:Object )      {
     super( NAME, viewComponent );
     peopleSearch.addEventListener( PeopleSearch.LOAD_CATEGORY_TREE, doTreeLoad );
}
      
override public function getMediatorName():String   {
     return NAME;
}
      
protected function get peopleSearch():PeopleSearch      {
     return viewComponent as PeopleSearch;
}

private function doTreeLoad(event:Event):void {
     sendNotification( ApplicationFacade.LOAD_CATEGORY_TREE );
}

Any help highly appreciated.

-Westside
5  Announcements and General Discussion / Architecture / Can't Update ComboBox after Remote Call on: November 26, 2008, 01:36:27
Hi,

I am new to PureMVC and Flex as well.

I have been struggling with this for a few hours and could use some assistance if possible.  I have a mediator called "HomePageMediator", this mediator is registered with a view component called "HomePage".  This registration happens in my "StartupCommand"

In "RemoteProxy.as"

// Result from Remote Call
public function result( event:Object ):void {   
    switch ( event.token.message.operation )   {
   case "getUSStates":
   sendNotification(STATES_LOADED)
    break;
    }
}

In "StartupCommand.as":
facade.registerMediator( new HomePageMediator( app.homePage ) );

In "HomePageMediator.as"
public function HomePageMediator( viewComponent:Object ) {
   super( NAME, viewComponent );
   homePage.addEventListener( HomePage.LOAD_STATES, onStates );

}

private function onStates( event:Event ):void   {
   sendNotification( ApplicationFacade.LOAD_STATES );
}
      
override public function listNotificationInterests():Array   {
   return [
      ApplicationFacade.LOAD_STATES,
      ApplicationFacade.STATES_LOADED
      ];
}
      
override public function handleNotification( note:INotification ):void      {
    switch ( note.getName() ){
   case ApplicationFacade.LOAD_STATES:
             .....
             break;
   
             case ApplicationFacade.STATES_LOADED:
      homePage.statesAC = note.getBody() as ArrayCollection;
      homePage.stateComboBox.dataProvider = note.getBody() as ArrayCollection;
   break;
   }
}

In "HomePage.mxml"
[Bindable] public var statesAC: ArrayCollection;


The STATES_LOADED case statement which appears in my "handleNotification" function seems to work, but my combo box does not get populated with the data returned from the Remote Service Call.  The Service call is working as I can see the data exist when I debug. 

I think am going wrong here "homePage.statesAC = note.getBody() as ArrayCollection;"  but I am not sure.

How do I map the result from the remote call to my combobox?  I assume the mediator I am using "HomePageMediator" should do this.

Sorry for the long post, hopefully it makes some sense.

-Westside
6  Announcements and General Discussion / Getting Started / Show Busy Cursor on Remote Call? on: November 25, 2008, 04:01:18
Hi,

I am working with remote objects and when I use the <mx:RemoteObject> tag there is a property called "showBusyCursor", this displays a little clock wheel that suggests the page is loading.   I am new to Flex for the most part and PureMVC but I have a "RemoteDelegate.as" Class that I am using and in it there I have the following code:

public function RemoteDelegate( responder:IResponder, url:String ) {
   ro = new RemoteObject();
   ro.destination = "ColdFusion";
   ro.source = url;
   ro.showBusyCursor = true;  // this does not work for some reason 
  this.responder = responder;
}

1. So, the first question is how can I get the showBusyCursor to work when I am creating my Remote Object through ActionScript as opposed to MXML.

2. How can I use a custom loader icon/animation/progress bar of some sort.  I would like to have some modal window popup  with a progress bar or something and say "Logging In"

Any help highly appreciated.

Thanks,

-Westside
Pages: [1]