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] 2
1  Announcements and General Discussion / General Discussion / Re: Notification received when child components aren't created yet on: October 25, 2008, 07:40:20
yea, i realize there wasn't enough context, but the short story is I ended up adding a FlexEvent.CREATION_COMPLETE listener to the view, then taking action.

thanks
2  Announcements and General Discussion / General Discussion / Notification received when child components aren't created yet on: October 24, 2008, 05:18:30
I have a view that extends VBox and contains a TabBar and a custom component.  The Mediator for this view (we'll call the view, FooView and FooViewMediator) receives a notification, which causes FooViewMediator to invoke FooView.update( items:ArrayCollection );

The 'update' method in FooView looks like:
:
<mx:Script>
  [Bindable] private var dpItems:ArrayCollection;

  public function update( items:ArrayCollection ) : void
  {
      dpItems = items;
     
      var index:int = tabBar.selectedIndex;

       // do stuff with the index
  }
</mx:Script>

<mx:TabBar id="tabBar" dataProvider="{dpItems}" />

The error I get is when I try and get the selectedIndex of the tabBar inside the 'update' method because 'tabBar' is still null.  I need the index to do something else in the view, however, the other custom component in the view is also still null.

I'm not sure how best to handle this.  I mean the FooView is not null which is how I was able to create the FooViewMediator. But now that the mediator is up it gets notifications, but it's child components in the FooView aren't ready. 

Suggestions?
3  Announcements and General Discussion / General Discussion / Consumers Connected for a Long Time - Where to keep them? on: October 02, 2008, 03:01:58
So I have a Consumer which "subscribes" to a JMS topic.  Initially I had this thing in a Proxy so that it could get results and update its data, etc.

However, I felt like using Commands was a better approach.  The problem with a command is we must not use it to maintain state.  So, I shouldn't keep the "Consumer" object in it....b/c later I need to invoke "Consumer.unsubscribe" to clean up my connection.

Any suggestions on this?
4  Announcements and General Discussion / General Discussion / Re: How to create sequential (queue) commands ? on: October 02, 2008, 02:59:54
I had the same question recently, ultimately I came up with my own MacroCommand.  I can't share the code but essentially it loop through the subcommands and set a "finished" function on the command and then execute the command.  The "finished" function is a way for the command to notify the MacroCommand that it has finished.  Then my MacroCommand basically keeps track of this and knows when to execute the next command.

Works well for me and my many async. requests!
5  Announcements and General Discussion / General Discussion / Best Approach for Managing User Navigation on: September 26, 2008, 03:07:04
My Flex application has two navigation controls that are always visible to the user.  At the top there is a bread crumb (http://blog.smashedapples.com/2008/06/flex-breadcrumb.html) and on the left side is an Accordion (similar to something in Microsoft Outlook, etc). 

Sample menu options might include:
Home
  File
    New
    Save
    Close
  Options
    Preferences
    About

The BreadCrumb navigator uses the menus defined above, the accordion is exactly the same except it does not have a "home".  So in the Accordion there are two "header" buttons (not sure what the top level button is that you click on), one says "File" and the other says "Options".  When the "File" accordion option is selected the user can see three "LinkButton" controls, one each for "New", "Save" and "Close".  Same goes for "Options" accordion button.

These two navigation controls are defined in my AppMain.mxml (the root Application).  Basically I need to keep track of where the user is in the view so that at some point a previously viewed view can be shown.  For example, image if the user goes to Preferences.  If they start changing values and then decide they don't want to do that, they can click a "cancel" button (on the Preferences screen) and the application should go back to showing whatever view they were in previously.

I should mention that the content area that takes up the majority of the display (to the right of the Accordion) is implemented as a ViewStack, so for example when you click on "Preferences" it's view is shown.
   
Any suggestions on the best way to do this?

I was going to have the navigation controls (BreadCrumb and Accordion) fire events from AppMain.mxml and let my ApplicationMediator.as handle them by saying "appMainView.viewStack.selectedIndex = 2" (something like that).  I was thinking about keeping some sort of view state in the proxy so when another view says "show previous view" (i.e. the user clicked cancel) the mediator can access the proxy find out what the previous view was and show it.

Just curious, what your thoughts are, have you done this, any tips???
6  Announcements and General Discussion / General Discussion / Best way to take single view to multiple views on: September 24, 2008, 06:36:43
I currently have a rather complex UI.  In it there is a particular view which has its own Proxy, Mediator and view components, but now I need to allow the user to multiple displays of it.  So instead of a single view, maybe I use a tabbed style view.

For example, say this view displays stats about ONE baseball team.  It lists players, batting averages, win/loss, etc.  If they want to look at another team there is a combo box and they select a team and click "update" and the view updates.

Now, I need to have N-number of these views displayed for different teams.  So, if I did a tabbed view they could have 3 tabs (for example), each tab displays stats for a different team.

Is there a recommended approach to refactoring my code to support this?  Right now it's all based on getting data and displaying data for one team.  Now it seems like I need a parent proxy (which handles giving data about a team to the correct child proxy) and a parent mediator and a parent view.

What do you think?
7  Announcements and General Discussion / General Discussion / Re: Chain Commands that Don't Execute Until Previous Command Does on: September 09, 2008, 10:13:06
My approach right now is to create my MacroCommand type of class that will pass a "finishedCallback" to each command before calling "execute" on it.  Then it sits until a command finishes, then calls the next one.  My subcommands actually modify the body of the notification as they move along.

works for me...anyone else try this?
8  Announcements and General Discussion / General Discussion / Chain Commands that Don't Execute Until Previous Command Does on: September 09, 2008, 08:38:55
I have a MacroCommand and it executes Command A, B, then C.  Currently B needs some data that A gets to do it's function.  However, A calls a remote object asynchronously so it's 'execute' method finishes quickly and the MacroCommand calls B.execute. 

Should I implement something that causes MacroCommand to wait for A to "finish" before calling B?  or Should I create a special Proxy that stores the temporary results for me?

Thanks!
9  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 07, 2008, 05:16:45
In response to #2.

So you are saying that the PersonView should fire an event once it's "onCreatationComplete" has been called right?

PersonView.mxml
:
<mx:Panel ... creationComplete="notify(event)" />

private function notify(event:FlexEvent):void {
      event.bubbles=true;
      dispatchEvent(event);
}

Then have the AppMediator (in this case) register for the "FlexEvent.CREATION_COMPLETE" for the "PersonView"?

Seems to be the same as what I already did except I removed the step of having the view catch the event and fire it.
10  Announcements and General Discussion / General Discussion / Removing Unused Mediators - should it be done when using ViewStack? on: August 07, 2008, 05:12:03
So there is a blog post about the "10 tips for working with PureMVC" (http://www.websector.de/blog/2007/12/25/10-tips-for-working-with-puremvc/).

Number 8 says:

In some cases you don’t use a Mediator and its View Components anymore. Then remove the Mediator using facade.removeMediator(MyMediator.NAME); in conjunction with a self created destroy() method to remove the ViewComponent including all listeners, timer, references, etc. for a successful garbage collection.

So with a ViewStack, when the user is no longer looking at a view is it best to remove the mediator, listeners, etc for the view that is no longer being displayed (b/c the user chose to view a different element of the ViewStack?
11  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 07, 2008, 04:21:28
Ok so I updated AppMediator to look like this:

:
protected function checkForMediator( childSelector:int, child:Object ):void {
    switch (childSelector) {
        case AppMain.VIEW_EMPLOYEES:
            if (facade.retrieveMediator(EmployeeViewMediator.NAME) == null) {
                facade.registerMediator(new EmployeeViewMediator(child));
            }
            break;
        case AppMain.VIEW_PERSON:
if (facade.retrieveMediator(PersonFormMediator.NAME) == null ||
facade.retrieveMediator(PersonListMediator.NAME) == null) {
var personView:PersonView = child as PersonView;
personView.addEventListener(FlexEvent.CREATION_COMPLETE, onPersonViewCreationComplete);
}
            break;
    }
}

private function onPersonViewCreationComplete(event:FlexEvent):void {
if (facade.retrieveMediator(PersonFormMediator.NAME) == null) {
var personView:PersonView = event.target as PersonView;
facade.registerMediator(new PersonFormMediator(personView.personForm));
}
if (facade.retrieveMediator(PersonListMediator.NAME) == null) {
var personView:PersonView = event.target as PersonView;
facade.registerMediator(new PersonListMediator(personView.personList));
}
}

That seems to work, just want to verify that is the suggested practice, is it?
12  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 07, 2008, 04:11:37
AppMain.mxml
 - ApplicationControlBar (has two buttons to change the viewstack)
 - a ViewStack with 2 views, EmployeeView and PersonView
 - has a mediator, AppMediator

PersonView.mxml
 - PersonForm (has a mediator)
 - PersonList (has a mediator)

The AppMediator gets called when the "Employee" or "Person" buttons are clicked (they toggle which view is shown in the ViewStack).  When the AppMediator gets the call it will call the "checkForMediator" function which works like:

:
protected function checkForMediator( childSelector:int, child:Object ):void {
    switch (childSelector) {
        case AppMain.VIEW_EMPLOYEES:
            if (facade.retrieveMediator(EmployeeViewMediator.NAME) == null) {
                facade.registerMediator(new EmployeeViewMediator(child));
            }
            break;
        case AppMain.VIEW_PERSON:
            if (facade.retrieveMediator(PersonFormMediator.NAME) == null) {
                var view:PersonView = child as PersonView;
                facade.registerMediator(new PersonFormMediator(view.personForm));
            }
            if (facade.retrieveMediator(PersonListMediator.NAME) == null) {
                var view:PersonView = child as PersonView;
                facade.registerMediator(new PersonListMediator(view.personList));
            }
            break;
    }
}

When the application first loads the EmployeeView is shown.  If click the "Person" button in the ApplicationControlBar then the PersonView should be shown.  However, when that action occurs the PersonFormMediator gets a null reference error because in its constructor it tries to do:

:
personForm.addEventListener(....);  // personForm is the PersonForm view

The suggestion here (http://forums.puremvc.org/index.php?topic=280.msg1200#msg1200) says to add an "onCreationComplete" event to the view component.  But how can my PersonFormMediator do that when the view object it is given is null?

Should I add the event listener from the AppMediator so that it listens for "onCreationComplete" from the "PersonView" and then when it does get the event, then create the PersonFormMediator and PersonListMediator?
13  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 07, 2008, 03:57:01
I did once but it would seem I haven't looked hard enough.

Gotta say a lot of the posts that come up have the end result of "search for deferred instantiation, you'll find the answer(s)".

 :)

Maybe there needs to be a "sticky" post that gives the answer in one place.
14  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 06, 2008, 11:53:12
Well I got that working but now I have the same in a slightly different way.

I have setup my code similar to the EmployeeAdmin demo.  So I have a PersonForm and PersonList in say "PersonView".  I also have "LoginView".  The LoginView and PersonView are in a ViewStack.  I have taken the steps (as shown earlier, in a slightly different example) to handle registering the mediator later.

However, in my PersonFormMediator the constructor gets a "null" view component.

The ApplicationMediator is doing the following in the checkForMediator:
:
        case AppMain.VIEW_PERSON:
if (facade.retrieveMediator(PersonFormMediator.NAME) == null) {
var personView:PersonView = child as PersonView ;
        facade.registerMediator(new PersonFormMediator(personView.personForm));
        }

For some reason the "personForm" is null.  Any ideas why??
15  Announcements and General Discussion / General Discussion / Re: Best Practice for storing currently selected item? on: August 06, 2008, 11:40:39
exactly what I am doing now :)
Pages: [1] 2