2 Replies Latest reply on Apr 29, 2009 11:59 AM by JCT01

    How do I avoid opening a new window each time I select an item from a Datagrid?

    JCT01

      I have created a simple app using the Coldfusion/Flex App Wizard. However I have yet to figure out how to avoid opening a new window each time I select an item from the datagrid. I want to simply refresh the window with the information pertinent to the selected item.

       

      <?xml version="1.0" encoding="utf-8"?>
      <cfComponents:SizeableTitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
      xmlns:cfComponents="com.adobe.ColdFusion.components.*"
      creationComplete="initComponent()"
      title="Spirits"
      showCloseButton="true" close="WindowManager.remove(this);" >

      <mx:Script>
        <![CDATA[
         import com.adobe.windowedApplication.managers.WindowManager;
         import mx.core.UIComponent;
         import mx.collections.ArrayCollection;
         import mx.utils.ObjectUtil;
         import mx.controls.Alert;
         import mx.rpc.events.FaultEvent;
         import mx.rpc.events.ResultEvent;
         import com.cfgenerated.views.masterdetail.SpiritsDetails;
         private var currentIndex:int = 0;

         private var _key:Object;

         [Bindable]
         public function get key():Object
         {
          return this._key;
         }
         public function set key(key:Object):void
         {
          this._key = key;
         }

         private function initComponent():void
         {
          refreshList(null);
         }

         public function refreshList(event:Event):void
         {
          this.dataManager.getMasterQuery(this.key);
         }

         private function getSpiritsDetailsComponent(key:Object):UIComponent
         {
          var view:SpiritsDetails = new SpiritsDetails();
          view.key = key;
          return view;
         }

         /**
          * RemoteObject result and error handlers
          */
         private function server_fault(event:FaultEvent):void
         {
          // dump error message
          Alert.show( ObjectUtil.toString(event.fault) );
         }

         private function getMasterQuery_result(event:ResultEvent):void
         {
          //Alert.show( ObjectUtil.toString(event.result) );
          this.masterList.dataProvider = event.result as ArrayCollection;
          this.masterList.selectedIndex = this.currentIndex;
         }

         private function deleteItem_result(event:ResultEvent):void
         {
          //Alert.show( ObjectUtil.toString(event.result) );
          refreshList(null);
         }
        ]]>
      </mx:Script>

      <mx:RemoteObject
        id="dataManager"
        showBusyCursor="true"
        destination="ColdFusion" source="test2.components.cfgenerated.Spirits">
        <mx:method name="getMasterQuery" result="getMasterQuery_result(event)" fault="server_fault(event)" />
        <mx:method name="deleteItem" result="deleteItem_result(event)" fault="server_fault(event)" />
      </mx:RemoteObject>

      <mx:HBox width="100%" height="100%">
        <mx:DataGrid
         id="masterList"
         width="100%" height="100%" top="0" left="0" right="0" bottom="0"


         click="WindowManager.add(getSpiritsDetailsComponent(this.masterList.selectedItem.BeverageI D), this, false);">


         <mx:columns>
          <mx:DataGridColumn dataField="Beverage" headerText="Beverage" />
         </mx:columns>
        </mx:DataGrid>

      </cfComponents:SizeableTitleWindow>