tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/362-extending-viewmediator-classesRobotlegs: Discussion 2011-12-23T08:42:46Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/95780892011-08-26T21:37:21Z2011-08-26T21:37:21ZExtending view/mediator classes<div><p>Hi,</p>
<p>My Problem: I have four different screens each showing different
data, but the base layout is same for all. So, I have a base class
which has the layout defined "BasePanel.as". Now all my panels
extend from this class. Similarly I have a 'BaseMediator.as' class
from which all the mediator classes extend.<br>
Assuming that I have two more panels for now (PanelA, PanelB -->
BasePanel similarly MediatorA, MediatorB --> BaseMediator)</p>
<h2>BaseMediator.as</h2>
<p>//In this class I am injecting the base panel and a reference to
app model (I expect the app model to be available to all extending
panels). [Inject] public var panelView:BasePanel;</p>
<p>[Inject] public var applicationModel:AppModel;</p>
<p>So in my 'context' I have mapped the panel to mediator as
below</p>
<p>mediatorMap.mapView(BasePanel, BaseMediator);<br>
mediatorMap.mapView(PanelA, MediatorA, [ PanelA, BasePanel ]);
//found this solution on the blog<br>
mediatorMap.mapView(PanelB, MediatorB, [ PanelB, BasePanel ]);</p>
<h2>And in my MediatorA.as</h2>
<p>//In this class I do not have Inject annotation again here for
'panelA'</p>
<p>//function to update view 'private function
updateDisplay(evt:UpdateEvent):void {</p>
<pre>
<code> (panelView as PanelA).dataGrid.dataProvider = evt.result; //Is casting to a sub class allowed ?</code>
</pre>
<p>}'</p>
<p>My strange experience here is, I get a run-time error
'TypeError: Error <a href="/discussions/problems/1006" title=
"Discussion #1006">#1006</a>: value is not a function.'</p>
<p>But, if I have a trace statement before I actually update the
dataProvider it works well.<br>
sth like this 'trace(" Ref to DataGrid " + (panelView as
PanelA).dataGrid)'</p>
<p>Question: Is my approach to inheritance is correct ? Am I
allowed to up-cast the reference of base class to sub class and do
some operations ? Why is that I don't see the type error 1006 when
I don't have a trace statement printing the reference to DataGrid
?</p>
<p>If there is a better way to solve my problem, let me know.</p>
<p>Thanks,<br>
Ravi</p></div>kotharavitag:robotlegs.tenderapp.com,2009-10-18:Comment/95780892011-08-28T12:55:49Z2011-08-28T12:55:49ZExtending view/mediator classes<div><p>I don't think it's necessary to map BasePanel to BaseMediator,
unless if you want to mediate a BasePanel instance separately.<br>
The error you're receiving has nothing to do with RL I think. Could
you post the entire stack trace?<br>
My guess is that the datagrid isn't initialized entirely before you
try to assign its dataprovider. Because of the trace there's a
small delay, which is enough to complete its initialization. But as
I said that's just a guess.</p></div>creynders