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]
16  Announcements and General Discussion / General Discussion / Best Practice for storing currently selected item? on: August 06, 2008, 09:15:32
I have a list and when I select an item I want to update a form.  So say the list has Person objects and when you select one a Form (in the same View) has a Name and Age field that get populated with the selected object.

Is it best to keep a, "private var selected:PersonVO" in the view or should I keep "selected" in the proxy?  If I keep it in the proxy, I'd have to have my view catch the "list change" event, fire off an event, the mediator would catch it and do "proxy.selected = view.list.selectedItem".  Then the proxy would maybe send out a notification, the mediator would catch the notification and populate the form.

Would the notification be defined in the ApplicationFacade?  (i.e. public static const PERSON_SELECTED:String ="personSelected");

Also, if it did go the route of sending an event and so on, I would need a "PersonSelectedCommand" right?  Since the mediator shouldn't talk directly to the proxy, it should use a notification.

Is one "better" than the other?
17  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 06, 2008, 08:24:20
Well instead of having my BarViewMediator do:

:
view.listBarObjects.dataprovider = data;

I instead put a bindable ArrayCollection in my BarView and bound the dataProvider of the list to it.

:
[Bindable] public var data:ArrayCollection = new ArrayCollection();
...
...
<mx:List id="listBarObjects" dataProvider={data}" />

Now in my BarViewMediator I have:

:
view.data = data;

and it works.
18  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 06, 2008, 08:19:04
So I followed he helpful information (for ViewStack at least): http://forums.puremvc.org/index.php?topic=280.0

However I still have the same problem.

ApplicationMediator
:
public function ApplicationMediator(viewComponent:Object=null)
{
super(NAME, viewComponent);

view.addEventListener(AppMain.EVT_SHOW_FOO, onShowFoo);
view.addEventListener(AppMain.EVT_SHOW_BAR, onShowBar);
checkForMediator(view.currentViewSelector, view.activeView);
}
protected function onShowFoo(e:Event):void {
view.currentViewSelector = AppMain.VIEW_FOO;
checkForMediator(AppMain.VIEW_FOO, view.activeView);
sendNotification(ApplicationFacade.FOO_MODE);
}
protected function onShowBar(e:Event):void {
view.currentViewSelector = AppMain.VIEW_BAR;
checkForMediator(AppMain.VIEW_BAR, view.activeView);
sendNotification(ApplicationFacade.BAR_MODE);
}
        protected function checkForMediator( childSelector:int, child:Object ):void {
        switch (childSelector) {
        case AppMain.VIEW_FOO:
        if (facade.retrieveMediator(FooViewMediator.NAME) == null) {
        facade.registerMediator(new FooViewMediator(child));
        }
        break;
        case AppMain.VIEW_BAR:
if (facade.retrieveMediator(BarViewMediator.NAME) == null) {
        facade.registerMediator(new BarViewMediator(child));
        }
        break;
        }
        }

AppMain.mxml
:
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
import mx.rpc.events.FaultEvent;

public static const EVT_SHOW_FOO:String = "showFoo";
public static const EVT_SHOW_BAR:String = "showBar";

public static const VIEW_FOO:int = 0;
public static const VIEW_BAR:int = 1;

[Bindable] public var currentViewSelector:int = VIEW_FOO;
public var activeView:Object = viewEvents;

private var facade:ApplicationFacade = ApplicationFacade.getInstance();

private function init():void {
activeView = viewStack.selectedChild;
facade.startup(this);
}

private function submit(action:String):void {
dispatchEvent(new Event(action, true));
}
]]>
</mx:Script>

<mx:Binding source="viewStack.selectedChild" destination="activeView" />

<mx:ApplicationControlBar id="appControlBar" width="65%" dock="true">
<mx:Button id="buttonFoo" label="Foo" click="submit(EVT_SHOW_FOO)" />
<mx:Button id="buttonBar" label="Bar" click="submit(EVT_SHOW_BAR)" />
</mx:ApplicationControlBar>

<mx:ViewStack id="viewStack" width="100%" height="75%"
selectedIndex="{currentViewSelector}">

<components:FooView id="viewFoo" width="100%" height="100%" />

<components:BarView id="viewBar" width="100%" height="100%" />
</mx:ViewStack>

So when the app first starts up you see the "FooView".  When I click on the "Bar" button I get the NULL reference error in my BarViewMediator when I try to set the dataProvider on my "listBarObjects":
BarViewMediator.as
:
public function BarViewMediator(viewComponent:Object=null) {
super(NAME, viewComponent);

var data:ArrayCollection = new ArrayCollection();
for (var i:int = 0; i < 5; i++) {
var q:BarVO = new BarVO ();
q.name = "Bar " + (i+1);
q.msg = "something random here - " + i;
data.addItem(q);
}

view.listBarObjects.dataProvider = data;
}

Did I miss something about how to handle this deferred instantiation?  When I debug I can see that the "checkForMediator" method gets called when I click the "Bar" button and I see it creates a new "BarViewMediator" and passes it the "BarView" object, however the "listBarObjects" is null.
19  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 05, 2008, 02:56:41
Sorry for the mix up.

I originally stated that the ApplicationMediator passes the FooView to the FooMediator by doing view.FooView

Application.mxml
:
<mx:application...>
    ...
    <components:FooView id="FooView" />
    ...
</mx:application>

ApplicationMediator.as
:
public function ApplicationMediator(...) {
   ...
   facade.registerMediator(new FooMediator(view.FooView));
}

private function get view():Application {
      return viewComponent as Application;
}

So I am passing in a FooView.
20  Announcements and General Discussion / General Discussion / Re: View component is null during startup? on: August 05, 2008, 01:32:38
I am using the standard version.

FooView is a child of the "view".

view.dummyButton is null but "view" is not (as i could see in the debugger).

Not really sure what the issue is.  Should I register the view.dummyButton.addEventListener somewhere else besides the constructor?  I think it's ok to do it in the constructor since I've done it elsewhere and the samples do it.

thanks.
21  Announcements and General Discussion / General Discussion / View component is null during startup? on: August 05, 2008, 11:55:05
I have the following setup:

StartupCommand creates ApplicationMediator
ApplicationMediator creates FooMediator (and passes it view.FooView)

The FooMediator constructor looks like:
:
public function FooMediator(viewComponent:Object=null) {
      super(NAME, viewComponent);
      view.dummyButton.addEventListener(....);
}

private function get view():FooView {
   return viewComponent as FooView;
}

I get the following on the "view.dummButton.addEventListener" line:
Cannot access a property or method of a null object reference.

In the debugger I see that "dummyButton" is null.

The FooView looks like:
:
<mx:Panel ....>
<mx:Button id="dummyButton" label="Close" />
</mx:Panel>

Any ideas?
22  Announcements and General Discussion / Getting Started / Re: Courseware? on: August 01, 2008, 04:17:09
I spoke (actually emailed) with Cliff about the disappearance of the courseware (I too had seen it referenced around on the 'net) and on July 24, 2008 he said:

Sorry, but the courseware beta test program has closed. The courseware is in the process of being updated now. Keep an eye out on the site for more info.
23  Announcements and General Discussion / General Discussion / FlexBuilder3 Error - 1017: The definition of base class Facade was not found. on: August 01, 2008, 04:12:21
I have a Flex project in FlexBuilder3 which also has a pom.xml.  I have added the following to my pom.xml:
:
<dependency>
<groupId>org.puremvc</groupId>
<artifactId>puremvc_as3</artifactId>
<version>2.0.3</version>
<classifier>swc</classifier>
</dependency>

However, FlexBuilder gives me two errors:
1017: The definition of base class Facade was not found.
1020: Method marked override must override another method.

The lines of code that those two errors reference to, respectively, are:
:
public class ApplicationFacade extends Facade
and
:
override protected function initializeController():void {

Do I need to add PureMVC to my "Flex Build Path" (i.e. under the "Properties" for my Flex project)?  If so, I thought by having Maven include the dependency I didn't need to do that.

Thanks!
Pages: 1 [2]