Solved

I'm don´t know what's happening with this code

Posted on 2009-04-04
10
602 Views
Last Modified: 2012-05-06
This application has two DataGrids as shown in the code below. When I select any item on the first Datagrid you will see the related data showed on the last datagrid...but, just the first time. Should I select any other line it's ok; however, returning to any previous-selected line do not execute the request..something fails. It Looks like repeating request over a line previously selected doesn't run.
B.T.W. I used also event "change" instead "click" and nothing,....same problem.
 
Tkanks for helping in advance.
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

	creationComplete="init()">

<!--

==============================================================================

This app uses three tables: "Products" 0===>> "Pack_prod" <<===0 "Packaging"

Structures:

	Products: Prodid(pk) + Descrip + .....

		|

		|===>> Pack_prod: (Prodid + Packid)(pk) + ...

					|

					|<<===0 Packaging: Packid(pk) + Descrip + ....  	
 

==============================================================================

-->	

	<mx:Script>

		<![CDATA[

			import weborb.events.PagingEvent;

			import mx.events.CollectionEvent;

			import mx.collections.ArrayCollection;

			import weborb.data.ActiveRecord;

			import Alcoxmlns.Packaging;

			import AlcoClasses.alert;

			import Alcoxmlns.Pack_prod;

			import Alcoxmlns.Productos;

			import Alcoxmlns.ActiveRecords;

			import weborb.data.DynamicLoadEvent ;

			import weborb.data.ActiveCollection;

			

			[Bindable] private var dataProd:ActiveCollection;

			[Bindable] private var packAC:ActiveCollection ;

			[Bindable] private var packrecord:Packaging ;

			[Bindable] private var tAC:ActiveCollection ;

			

			//  Inicialization

			private function init():void{

				packAC 	= new ActiveCollection ;

				dataProd = new ActiveCollection();

				dataProd = ActiveRecords.Productos.findAll({PageSize:20});

				dataProd.addEventListener(DynamicLoadEvent.LOADED,onLoadeProd);	

			}

			

			private function onLoadeProd(event:DynamicLoadEvent):void{

				

			}

			

			// This function processes any changes on datagrid DG

			private function onSelectDG(event:Event):void{

				tAC 	= new ActiveCollection();

				var producto:Productos = DG.selectedItem as Productos ;

				packAC 	= producto.RelatedPack_prod as ActiveCollection ;

				packAC.addEventListener(CollectionEvent.COLLECTION_CHANGE,onChangePP);

				packAC.addEventListener("loaded",onLoadedPP);

			}

			// This function processes each row of PackAC to find packaging related

			private function onChangePP(event:CollectionEvent):void{

				var pprecord:Pack_prod 	= event.items[0] as Pack_prod;

				var packrec:Packaging 	= pprecord.RelatedPackaging ;

				tAC.addItem(packrec);

			}

			

			private function onLoadedPP(event:DynamicLoadEvent):void{				

								

			}

			

		]]>

	</mx:Script>

	<mx:DataGrid id="DG" x="10" y="10" width="795" height="195"

		dataProvider="{dataProd}"

		click="onSelectDG(event)">

		<mx:columns>

			<mx:DataGridColumn headerText="ProdId" dataField="Prodid"/>

			<mx:DataGridColumn headerText="Description" dataField="Descrip"/>

		</mx:columns>

	</mx:DataGrid>

	<mx:DataGrid id="DGpack" x="10" y="213" width="591" height="146"

		dataProvider="{tAC}">

		<mx:columns>

			<mx:DataGridColumn headerText="Packid" dataField="Packid"/>

			<mx:DataGridColumn headerText="Descripcion" dataField="Descrip"/>

		</mx:columns>

	</mx:DataGrid>

</mx:Application>

Open in new window

0
Comment
Question by:cpach115
  • 5
  • 5
10 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 24074895
What is the goal of this instruction:
>> packAC.addEventListener(CollectionEvent.COLLECTION_CHANGE,onChangePP);

I would expect that changing the selection in "DG" should trigger a change in "DGpack",
hence why don't you let onSelectDG() change tAC (being the dataprovider of DGpack) immediately?
Why do you work with that extra listener?
0
 

Author Comment

by:cpach115
ID: 24078409
Ok..you are right. I deleted the "change" listener and got the same result as before. However, how can I show the "descrip" field in table "Packaging" using packAC as ActiveCollection of kind Pack_prod?.
 I need a new Array or ActiveCollection (tAC) to find "Descrip" in "RelatedPackaging" and using it as a dataprovider.

When use the code in comments, works ok showing me all fields but just the first time. Changing dataProvider of DGpack solves the "first time only" problem but can't display Descrip field resident in
"Packaging" table.

Do you know another way?....

Thanks for your good help.
			//  Inicialization

			private function init():void{

				packAC 	= new ActiveCollection ;

				dataProd = new ActiveCollection();

				dataProd = ActiveRecords.Productos.findAll();

			}

			

			// This function processes any changes on datagrid DG

			private function onSelectDG(event:Event):void{

				packAC = new ActiveCollection();

				var producto:Productos = DG.selectedItem as Productos ;

				packAC 	= producto.RelatedPack_prod as ActiveCollection ;

 			/*	packAC.addEventListener("loaded", 

                                       function (e:DynamicLoadEvent):void{

 					 tAC = new ActiveCollection();

					for(var i:uint=0;i < packAC.length;i++){

					   tAC.addItem(packAC[i].RelatedPackaging );

					}

					tAC.refresh(); 

					DGpack.validateNow(); 	 	

				}); */  

 			}

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24081245
>> Ok..you are right. I deleted the "change" listener and got the same result as before.
I asked you what the intention of the listener was... and you remove it and tell that it still doesn't work.
That's not the way to go.

For being able to help you, I'm trying to understand what you're trying to do.
So my question stays: what was your goal in using that event listener?
Please translate that even listener in comment in plain english. What are you trying to do over there?

Remark:
Why would you have this line
>> dataProd = new ActiveCollection();
immediately followed by this:
>> dataProd = ActiveRecords.Productos.findAll();

That 1st line is completely obsolete.

Try this:

private function onSelectDG(event:Event):void{
   var producto:Productos = DG.selectedItem as Productos ;
   packAC  = producto.RelatedPack_prod as ActiveCollection ;
   var tmpAc:ActiveCollection = new ActiveCollection();
   for(var i:uint=0;i < packAC.length;i++){
      tmpAc.addItem(packAC[i].RelatedPackaging );
   }
   tAC = tmpAc;
   tAC.refresh();
}
0
 

Author Comment

by:cpach115
ID: 24081836
Thanks zzynx.

I apologize for my broken and not good english. Well, let me explain it better.
I have a "Products" table as shown in first datagrid. The second datagrid (DGpack) must show accesories or packaging that belongs to the product selected above. In order to normalize the database the "Descrip" field belongs to the "Packaging Table". It's not IN "Pack_prod table" (see the diagram in comment). Misteryously, when using ".RelatedPackaging"...."descrip" IS NULL but in database has value.

I used your suggestion code and it showed me the correct id of the packaging but NOT the DESCRIPTION.....
Like it happens to me. The only way that I  can see the "descrip field" is using that listener in comments in my code.
But, I lost the trigger.

Got it???



Dibujo.jpg
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24084508
>> I apologize for my broken and not good english.
No problem.

>> I used your suggestion code and it showed me the correct id of the packaging
So that means that the filling up of the 2nd table based on the selection in the 1st table works OK.
We certainly have to keep that.

Now, the next problem is
>> Misteryously, when using ".RelatedPackaging"...."descrip" IS NULL but in database has value.
That sounds as an initialization/filling up problem.
Can you show me the code where your fill up that RelatedPackaging attribute of Productos.RelatedPack_prod?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:cpach115
ID: 24087408
Thanks.

Yes, It is. I'm sure but then It's a "IsLoaded" issue.
I'll show you three packages illustrating this. "Pack_prod.as", its extend "_Pack_prod.as" and "_Packaging.as". Both of them were created by "Weborb php 3.5" codegen.

It was the reason for me to use an event listener "loaded" (DynamicLoadEvent).

Try to follow this variable:
// parent tables
         internal var _relatedPackaging:Packaging = new Packaging();


1) Pack_prod.as:
 

package Alcoxmlns

      {

        import Alcoxmlns.Codegen.*;

        

        [Bindable]

        [RemoteClass(alias="Alcoxmlns.Pack_prod")]

        public dynamic class Pack_prod extends _Pack_prod

        {

        

        }

      }
 

2) _Pack_prod.as:
 

   package Alcoxmlns.Codegen

   {

      import weborb.data.*;

      import Alcoxmlns.*;

      import mx.collections.ArrayCollection;

      import flash.utils.ByteArray;
 

      [Bindable]

      public dynamic class _Pack_prod extends ActiveRecord

      {
 

        public function get ActiveRecordUID():String

        {

          return _activeRecordId;

        }
 

        public function set ActiveRecordUID(value:String):void

        {

          _activeRecordId = value;

        }
 

         private var _uri:String = null;
 

         protected var _packid:int;

         protected var _prodid:int;
 

         // parent tables

         internal var _relatedPackaging:Packaging = new Packaging();
 

         // parent tables

         internal var _relatedProductos:Productos = new Productos();
 

         public function get Packid():int

         {

             if(_relatedPackaging != null)

                return _relatedPackaging.Packid;
 

            return undefined;

         }
 

         protected function set Packid(value:int):void

         {

             if(_relatedPackaging == null)

                _relatedPackaging = new Packaging();

           

		  _relatedPackaging.Packid = value;

           _isPrimaryKeyAffected = true;

           _uri = null;

         }
 

         public function get Prodid():int

         {

             if(_relatedProductos != null)

                return _relatedProductos.Prodid;
 

            return undefined;

         }
 

         protected function set Prodid(value:int):void

         {

             if(_relatedProductos == null)

                _relatedProductos = new Productos();

           

		  _relatedProductos.Prodid = value;

           _isPrimaryKeyAffected = true;

           _uri = null;

         }
 

         public function get RelatedPackaging():Packaging

         {

           if(IsLoaded && !(_relatedPackaging.IsLoaded || _relatedPackaging.IsLoading))

           {
 

             var oldValue:ActiveRecord = _relatedPackaging;
 

             _relatedPackaging = DataMapperRegistry.Instance.Packaging.load(_relatedPackaging);
 

             if(oldValue != _relatedPackaging)

               onParentChanged(oldValue, _relatedPackaging);          
 

           }
 

           return _relatedPackaging;

         }
 

         public function set RelatedPackaging(value:Packaging):void

         {

            if( value != null )

            {

               var oldValue:ActiveRecord = _relatedPackaging;

          	

               _relatedPackaging = Packaging(IdentityMap.register( value ));
 

               if(oldValue != _relatedPackaging)

                 onParentChanged(oldValue, _relatedPackaging);

            }

            else

              _relatedPackaging = null;

         }

         public function get RelatedProductos():Productos

         {

           if(IsLoaded && !(_relatedProductos.IsLoaded || _relatedProductos.IsLoading))

           {
 

             var oldValue:ActiveRecord = _relatedProductos;
 

             _relatedProductos = DataMapperRegistry.Instance.Productos.load(_relatedProductos);
 

             if(oldValue != _relatedProductos)

               onParentChanged(oldValue, _relatedProductos);          
 

           }
 

           return _relatedProductos;

         }
 

         public function set RelatedProductos(value:Productos):void

         {

            if( value != null )

            {

               var oldValue:ActiveRecord = _relatedProductos;

          	

               _relatedProductos = Productos(IdentityMap.register( value ));
 

               if(oldValue != _relatedProductos)

                 onParentChanged(oldValue, _relatedProductos);

            }

            else

              _relatedProductos = null;

         }
 

        protected override function onDirtyChanged():void

        {

            if(RelatedPackaging != null)

              RelatedPackaging.onChildChanged(this);

            if(RelatedProductos != null)

              RelatedProductos.onChildChanged(this);

        }
 

        public override function extractRelevant(cascade:Boolean = false):Object

        {

          var object:Pack_prod = new Pack_prod();
 

              object.Packid = this.Packid;

              object.Prodid = this.Prodid;

         object.ActiveRecordUID = this.ActiveRecordUID;

         

         return object;

       }
 

          public override function applyFields(object:Object):void

          {

             if(!IsPrimaryKeyInitialized)

               Packid = object["Packid"];
 

             if(!IsPrimaryKeyInitialized)

               Prodid = object["Prodid"];
 
 

             RelatedPackaging = object.RelatedPackaging;
 

             RelatedProductos = object.RelatedProductos;
 

             _uri = null;

             _isPrimaryKeyAffected = true;

             IsDirty = false;

          }
 

        protected override function get dataMapper():DataMapper

        {

          return DataMapperRegistry.Instance.Pack_prod;

        }

        

        public override function getURI():String

        {
 

          if(_uri == null)

          {

             _uri = "alco.pack_prod" + "." + Packid.toString() + "." + Prodid.toString();

          }

           

          return _uri;

        }
 

      }

   }
 

3) _Packaging.as:
 

   package Alcoxmlns.Codegen

   {

      import weborb.data.*;

      import Alcoxmlns.*;

      import mx.collections.ArrayCollection;

      import flash.utils.ByteArray;
 

      [Bindable]

      public dynamic class _Packaging extends ActiveRecord

      {
 

        public function get ActiveRecordUID():String

        {

          return _activeRecordId;

        }
 

        public function set ActiveRecordUID(value:String):void

        {

          _activeRecordId = value;

        }
 

         private var _uri:String = null;
 

         protected var _packid:int;

         protected var _descrip:String;

         protected var _provid:String;

         protected var _precioref:Number = 0;

         protected var _tipo:String;

         protected var _status:String;
 

         // parent tables

         internal var _relatedProveedores:Proveedores;
 

         public function get Packid():int

         {

           return _packid;

         }
 

         public function set Packid(value:int):void

         {

            _isPrimaryKeyAffected = true;

            _uri = null;
 

            if(IsLoaded || IsLoading)

            {

              trace("Critical error: attempt to modify primary key in initialized object " + getURI());

              return;

            }

            _packid = value;

         }
 

         public function get Descrip():String

         {

           return _descrip;

         }
 

         public function set Descrip(value:String):void

         {

            _descrip = value;

         }
 

         public function get Provid():String

         {

             if(_relatedProveedores != null)

                return _relatedProveedores.Provid;
 

            return undefined;

         }
 

         protected function set Provid(value:String):void

         {

             if(_relatedProveedores == null)

                _relatedProveedores = new Proveedores();

           

		  _relatedProveedores.Provid = value;

         }
 

         public function get Precioref():Number

         {

           return _precioref;

         }
 

         public function set Precioref(value:Number):void

         {

            _precioref = value;

         }
 

         public function get Tipo():String

         {

           return _tipo;

         }
 

         public function set Tipo(value:String):void

         {

            _tipo = value;

         }
 

         public function get Status():String

         {

           return _status;

         }
 

         public function set Status(value:String):void

         {

            _status = value;

         }
 

         public function get RelatedProveedores():Proveedores

         {

           if(IsLoaded && _relatedProveedores && !(_relatedProveedores.IsLoaded || _relatedProveedores.IsLoading))

           {
 

             var oldValue:ActiveRecord = _relatedProveedores;
 

             _relatedProveedores = DataMapperRegistry.Instance.Proveedores.load(_relatedProveedores);
 

             if(oldValue != _relatedProveedores)

               onParentChanged(oldValue, _relatedProveedores);          
 

           }
 

           return _relatedProveedores;

         }
 

         public function set RelatedProveedores(value:Proveedores):void

         {

            if( value != null )

            {

               var oldValue:ActiveRecord = _relatedProveedores;

          	

               _relatedProveedores = Proveedores(IdentityMap.register( value ));
 

               if(oldValue != _relatedProveedores)

                 onParentChanged(oldValue, _relatedProveedores);

            }

            else

              _relatedProveedores = null;

         }
 

            // one to many relation

            protected var _relatedOrdprdpack:ActiveCollection;

            

            public function get RelatedOrdprdpack():ActiveCollection

            {

              _relatedOrdprdpack = onChildRelationRequest("relatedOrdprdpack",_relatedOrdprdpack);

              

              return _relatedOrdprdpack;

            }
 

            // one to many relation

            protected var _relatedPack_prod:ActiveCollection;

            

            public function get RelatedPack_prod():ActiveCollection

            {

              _relatedPack_prod = onChildRelationRequest("relatedPack_prod",_relatedPack_prod);

              

              return _relatedPack_prod;

            }
 

            // one to many relation

            protected var _relatedPo_pack:ActiveCollection;

            

            public function get RelatedPo_pack():ActiveCollection

            {

              _relatedPo_pack = onChildRelationRequest("relatedPo_pack",_relatedPo_pack);

              

              return _relatedPo_pack;

            }
 

            // one to many relation

            protected var _relatedStock_pack:ActiveCollection;

            

            public function get RelatedStock_pack():ActiveCollection

            {

              _relatedStock_pack = onChildRelationRequest("relatedStock_pack",_relatedStock_pack);

              

              return _relatedStock_pack;

            }
 

        protected override function onDirtyChanged():void

        {

            if(RelatedProveedores != null)

              RelatedProveedores.onChildChanged(this);

        }
 

        public override function extractRelevant(cascade:Boolean = false):Object

        {

          var object:Packaging = new Packaging();
 

              object.Packid = this.Packid;

              object.Descrip = this.Descrip;

              object.Provid = this.Provid;

              object.Precioref = this.Precioref;

              object.Tipo = this.Tipo;

              object.Status = this.Status;
 

              if(cascade)

              {

                  for each(var ordprdpack:Ordprdpack in _relatedOrdprdpack)

                  {

                    if(ordprdpack.IsDirty)

                    {

                       var ordprdpackExtract:Object = ordprdpack.extractRelevant(true);

                           ordprdpackExtract._relatedPackaging = object;
 

                       object.RelatedOrdprdpack.addItem(ordprdpackExtract);

                    }

                  }
 

                  for each(var pack_prod:Pack_prod in _relatedPack_prod)

                  {

                    if(pack_prod.IsDirty)

                    {

                       var pack_prodExtract:Object = pack_prod.extractRelevant(true);

                           pack_prodExtract._relatedPackaging = object;
 

                       object.RelatedPack_prod.addItem(pack_prodExtract);

                    }

                  }
 

                  for each(var po_pack:Po_pack in _relatedPo_pack)

                  {

                    if(po_pack.IsDirty)

                    {

                       var po_packExtract:Object = po_pack.extractRelevant(true);

                           po_packExtract._relatedPackaging = object;
 

                       object.RelatedPo_pack.addItem(po_packExtract);

                    }

                  }
 

                  for each(var stock_pack:Stock_pack in _relatedStock_pack)

                  {

                    if(stock_pack.IsDirty)

                    {

                       var stock_packExtract:Object = stock_pack.extractRelevant(true);

                           stock_packExtract._relatedPackaging = object;
 

                       object.RelatedStock_pack.addItem(stock_packExtract);

                    }

                  }
 

              }
 

         object.ActiveRecordUID = this.ActiveRecordUID;

         

         return object;

       }
 

          public override function extractChilds():Array

          {

             var childs:Array = new Array();
 
 

             if(this["relatedOrdprdpack"])

             {

               for each(var ordprdpack:ActiveRecord in this["relatedOrdprdpack"] as Array)

                  childs.push(ordprdpack);

             }
 

             if(this["relatedPack_prod"])

             {

               for each(var pack_prod:ActiveRecord in this["relatedPack_prod"] as Array)

                  childs.push(pack_prod);

             }
 

             if(this["relatedPo_pack"])

             {

               for each(var po_pack:ActiveRecord in this["relatedPo_pack"] as Array)

                  childs.push(po_pack);

             }
 

             if(this["relatedStock_pack"])

             {

               for each(var stock_pack:ActiveRecord in this["relatedStock_pack"] as Array)

                  childs.push(stock_pack);

             }
 

             return childs;

          }
 

          public override function applyFields(object:Object):void

          {

             if(!IsPrimaryKeyInitialized)

               Packid = object["Packid"];
 

             Descrip = object["Descrip"];

             Provid = object["Provid"];

             Precioref = object["Precioref"];

             Tipo = object["Tipo"];

             Status = object["Status"];
 

             RelatedProveedores = object.RelatedProveedores;
 

             _uri = null;

             _isPrimaryKeyAffected = true;

             IsDirty = false;

          }
 

        protected override function get dataMapper():DataMapper

        {

          return DataMapperRegistry.Instance.Packaging;

        }

        

        public override function getURI():String

        {
 

          if(_uri == null)

          {

             _uri = "alco.packaging" + "." + Packid.toString();

          }

           

          return _uri;

        }
 

      }

   }

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24088254
Sorry. I can't follow that code...
0
 

Author Comment

by:cpach115
ID: 24088530
Ok....thanks zzynx.
I think this is a "themidnightcoders"'s issue. I'll try with them.
Lacking of documentation is the main problem.
0
 

Author Comment

by:cpach115
ID: 24589686
Well, I'll close this issue...
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 24590107
OK
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now