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: Injecting data to a viewComponent  (Read 13506 times)
justSteve
Courseware Beta
Sr. Member
***
Posts: 55


View Profile Email
« on: May 31, 2008, 05:33:53 »

I have the connections in place that correctly;
  • loads xml data to the proxy;
    connects mediator to proxy
    connects viewComponent to mediator

Now I'm trying to get the mediator to pass the proxy's data to the viewComponent:
this.mainMenu.loadXML(this.menuProxy.getMenuData() as XMLList);

The above statement executes from the mediator after the viewComponent fire's it's CreationComplete event. Using breakpoints, everything is happening in correct order - the data in the proxy exists correctly when the getMenuData() method is called:
   public function getMenuData( ):*
   {
      return data;
   }

But the parameter passed to the viewComponent's method is coming up NULL.
   public function loadXML(  value:XMLList ):void
   {
      nav.dataProvider="{_navXML}";
   }

So the question boils down to, is this not a legit way to pass data down to a view component?
this.mainMenu.loadXML(this.menuProxy.getMenuData() as XMLList);

Thinking it might be a conversion of type issue, I've also tried:

(proxy)
public function getMenuData( ):*
{
   return data as XMLList;
}   

(mediator)
this.mainMenu.loadXML(this.menuProxy.getMenuData());

Data looks ok all the way to the final step where it's passed into the viewComponent.

thx
--steve...
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 31, 2008, 08:34:41 »

The proxy method should have an XMLList return type (in the signature) and you won't have to cast to XMLList in the Mediator.

Then, the easiest thing is to expose a bindable public var of type XMLList in the view component. Use data binding to get into the dataprovider of the appropriate control.

You can use a method to set a bindable private var as you appear to be trying but its just more clutter if you're only setting the private var. If you have to expose a public member, a prop is as good as a method. (And a wink's as good as a nudge to a blind bat...)

But either war should work. I think its failing because of this syntax:

public function loadXML(  value:XMLList ):void   {      nav.dataProvider="{_navXML}";   

The curlies around the _navXML make no sense in this context. It looks as if you're trying to use an MXML binding in ActionScript.

But it does parse. Its shorthand for object creation, so you have created a new object with a property of _navXML that has no value, setting that as the dataProvider for your control. Try dropping the curlies.

-=Cliff>
Logged
justSteve
Courseware Beta
Sr. Member
***
Posts: 55


View Profile Email
« Reply #2 on: June 01, 2008, 04:38:48 »

Yep...those curlies shouldn't have been included in my question text. That statement only exists at this point to provide a breakpoint point - the malfunction is happening somewhere/sometime before that - when I breakpoint on my misguided curly statement and look at the 'value' parameter - it says 'null'.

But when the mediator attempted the injection:
   this.mainMenu.loadXML(this.menuProxy.getMenuData());

the data existed correctly in both type and content in the Proxy...it's just not getting returned out of the proxy correctly.

I've tried creating a public var in the mediator so as to store the value there with the intent of having the viewComponent retrieve that value (rather than being injected with it) - that changes the existing statement:

this.mainMenu.loadXML(this.menuProxy.getMenuData());

to:

this.mData = this.menuProxy.getMenuData();

Again....the data exists as expected in the proxy when the
   return data as XMLList;
statement is hit (also changed that method's return value to XMLList as suggested)

But mData in the Mediator comes up null just like it had when injected to viewComponent.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: June 01, 2008, 06:13:35 »

Sounds like you need to back the breakpoint back to the Proxy method and step through from there. It won't do any good breapointing after the data is already lost.

-=Cliff>
Logged
justSteve
Courseware Beta
Sr. Member
***
Posts: 55


View Profile Email
« Reply #4 on: June 02, 2008, 05:42:30 »

Turns out the data's dropped whereever the attempt to convert to
XMLList sits. As long as I leave it as Object, data's passed from
class to class as expected.

It sure seems like this failure to convert is something that
FlexBuilder should be notifying me of in some form or fashion,
shouldn't it?

thx much Cliff..._now I get to play with the pipes demo.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: June 02, 2008, 11:53:26 »

Steve,

I wonder if you specified 'E4X' as your return type in the HttpService used to grab the XML? I think the default is Object so that might play a part...
-=Cliff>
Logged
justSteve
Courseware Beta
Sr. Member
***
Posts: 55


View Profile Email
« Reply #6 on: June 02, 2008, 07:56:23 »

Here's the xml block:
         // constructor will store a reference to the service we're going to call
         this.service = new HTTPService();
         this.service.resultFormat = 'xml';
         this.service.url = url;
         
         // and store a reference to the proxy that created this delegate
         this.responder = responder;


The xml is coming as XMLNode (a top-level single node wrapping list of childNodes...in many other contexts - an XMLList. So the attempt to cast from an xmlnode to xmllist failed - and failed silently? It would be interesting to know if a Try/Catch wrapper ..um....could.
So anyway... the point is that the object returned from the http call came in as xml but was 'passible' as Object (not as XMLList) all the way to the dataprovider as Object. The original blog/tute/demo code is a sweet auto-scrolling menu demo pasted below via http://www.useflashmore.com/flex-as3-scrollable-accordion-menu/scrollable-accordion-menu-custom-component/main.html). It's able to sort out a number of contingent parameter objects that might be passed it's way and adjust on the fly.

But before pasting that - answer me this....wouldn't it be reasonable to expect to be alerted to such a failure to convert? Even if the try/catch traps it, ...really...i need to trap that tightly? or just log/trace better?

       //----------------------------------
       //  dataProvider
       //----------------------------------   
      
public function get dataProvider():Object {
   return _collection;
}                  
public function set dataProvider(value:Object):void {
if (_collection)
{
    _collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
}

if (value is Array)
{
    _collection = new ArrayCollection(value as Array);
}
else if (value is ICollectionView)
{
    _collection = ICollectionView(value);
}
else if (value is XMLList)
{
    _collection = new XMLListCollection(value as XMLList);
}
else if (value is XML)
{
    var xl:XMLList = new XMLList();
    xl += value;
    _collection = new XMLListCollection(xl);
}
else
{
    // convert it to an array containing this one item
    var tmp:Array = [];
    if (value != null)
        tmp.push(value);
    _collection = new ArrayCollection(tmp);
}
// get an _iterator for the displaying rows.  The CollectionView's
// main _iterator is left unchanged so folks can use old DataSelector
// methods if they want to
_iterator = _collection.createCursor();
_dataProviderChanged = true;

_collection.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler, false, 0, true);

var event:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
event.kind = CollectionEventKind.RESET;
collectionChangeHandler(event);
dispatchEvent(event);

invalidateProperties();
invalidateSize();
invalidateDisplayList();
}      

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



View Profile WWW Email
« Reply #7 on: June 03, 2008, 05:20:04 »

I agree it would be reasonable to be alerted. You should post to bugs.adobe.com if you can boil all this down to something concise enough for them to deal with.

In the meantime, set your resultFormat='e4x'

-=Cliff>
Logged
Pages: [1]
Print