tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/243-multiple-instances-of-viewsRobotlegs: Discussion 2018-10-18T16:35:21Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/46518402011-01-10T10:02:14Z2011-01-10T10:03:56ZMultiple instances of views<div><p>I have multiple views where I create multiple instances of the
view. The issue I am having is that all mediators mapped to this
view are responding to this event.</p>
<p>As an example:</p>
<p>I have created 3 different instances of the view TransactionMain
which is mapped to TransactionMainMediator.</p>
<p>When I dispatch the event CreateTransactionSend from the view,
all 3 instances of the mediator relay this information to the
service, so I wind up with 3 records created.</p>
<p>On response from the service, I dispatch another event, letting
the mediator/view know that the service transaction is complete. I
have created a simple alert to test. In all tests I get 3 alert
windows.</p>
<p>I have verified that I have set the event up to be
non-bubbling.</p>
<p>Here is a snippet of my code:</p>
<p>Event:</p>
<p>`</p>
<pre>
<code> package com.etdm.event.transaction
{
import com.etdm.vo.transaction.TransactionMain;
import flash.events.Event;
public class TransactionMainEvent extends Event
{
public static const CREATE_TRANSACTION_SEND:String = "CreateTransactionSend";
public static const CREATE_TRANSACTION_COMPLETE:String = "CreateTransactionComplete";
public var transactionMain:TransactionMain;
public function TransactionMainEvent(type:String, cancelable:Boolean=false, transactionMain:TransactionMain=null)
{
super(type, bubbles, cancelable);
transactionMain = transactionMain
}
public override function clone():Event
{
return new TransactionMainEvent( type, bubbles, cancelable, transactionMain);
}
}
}</code>
</pre>
<p>`</p>
<p>View Dispatching Function:</p>
<p>`</p>
<pre>
<code> private function nTest():void
{
var tMain:TransactionMain = new TransactionMain();
tMain.FileNumber = 1001;
var dataEvent:TransactionMainEvent = new TransactionMainEvent(TransactionMainEvent.CREATE_TRANSACTION_SEND,false);
dataEvent.transactionMain = tMain;
dispatchEvent(dataEvent);
}</code>
</pre>
<p>`</p>
<p>Mediator</p>
<p>`</p>
<pre>
<code> package com.etdm.mediator.admin.transaction
{
import com.etdm.event.transaction.TransactionMainEvent;
import com.etdm.service.transaction.ITransactionMainService;
import com.etdm.view.admin.transaction.TransactionGeneral;
import org.robotlegs.mvcs.Mediator;
public class TransactionGeneralMediator extends Mediator
{
[Inject]
public var view:TransactionGeneral;
[Inject]
public var transactionMainService:ITransactionMainService;
public function TransactionGeneralMediator()
{
super();
}
override public function onRegister():void
{
eventMap.mapListener(view, TransactionMainEvent.CREATE_TRANSACTION_SEND, OnCreateTransactionSend);
}
private function OnTransactionMainSend(event:TransactionMainEvent):void
{
transactionMainService.CreateTransactionMain(event.transactionMain);
}
}
}</code>
</pre>
<p>`</p></div>rottmanj