0 Replies Latest reply on Jan 24, 2011 1:16 AM by Flex_Crazy

    How To Populate An Advanced Data Grid In Flex With An XML Document Created In JAVA

    Flex_Crazy

      Flex Code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="856" height="698" initialize="onInitData()">

       

          <mx:RemoteObject destination="utilityUCFlexRO" id="utilityUCFlexRO">
              <mx:method name="updateStationDetails" result="handleUpdateStationDetailsResult(event)" fault="handleUpdateStationDetailsFault(event)"/>
          </mx:RemoteObject>
          <mx:RemoteObject id="uniqueIdMasterUCFlexRO" destination="uniqueIdMasterUCFlexRO">
              <mx:method name="readByCustomerName" result="handleReadByCustomerNameResult(event)" fault="handleReadByCustomerNameFault(event)"/>
              <mx:method name="getCustomerAcDetails" result="handlegetCustomerAcDetailsResult(event)" fault="handlegetCustomerAcDetailsFault(event)"/>
          </mx:RemoteObject>

       

          <mx:Script>
              <![CDATA[
                 
                  import mx.events.ListEvent;
                  import mx.collections.ItemResponder;
                  import com.citizen.cbs.model.UniqueIdMaster;
                  import mx.managers.PopUpManager;
                  import mx.controls.ProgressBarMode;
                  import mx.effects.Fade;
                  import mx.controls.ProgressBar;
                  import com.citizen.cbs.CitizenApplication;
                  import mx.core.Application;
                  import mx.messaging.messages.ErrorMessage;
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.ResultEvent;
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                 
                  private var moduleCloseFlag:Boolean=false;
                 
                  private var v:UniqueIdMaster;
                 
                  [Bindable]
                  private var customerDetails:ArrayCollection;
                  [Bindable]
                  private var branch:int=0;
                 
                  [Bindable]
                  private var XMLDocument:XML;
                 
                  [Bindable]
                  private var acDetails:XMLList;
                 
                 
                  private var _progBar:ProgressBar = new ProgressBar();
                 
                  private function showLoading(e:Event = null):void
                  {
                      _progBar.width = 200;
                      _progBar.indeterminate = true;
                      _progBar.labelPlacement = 'center';
                      _progBar.setStyle("removedEffect", Fade);
                      _progBar.setStyle("addedEffect", Fade);
                      _progBar.setStyle("color", 0xFFFFFF);
                      _progBar.setStyle("borderColor", 0x000000);
                      _progBar.setStyle("barColor", 0x6699cc);
                      _progBar.label = "Please wait.......";
                      _progBar.mode = ProgressBarMode.MANUAL;
                      PopUpManager.addPopUp(_progBar,this,true);
                      PopUpManager.centerPopUp(_progBar);
                      _progBar.setProgress(0, 0);
                 }
                 
                  private function onInitData():void
                  {
                      utilityUCFlexRO.updateStationDetails(CitizenApplication.menuParameters["modulecode"]);
                  }
                 
                  private function handleUpdateStationDetailsResult(event:ResultEvent):void
                  {
                      if(moduleCloseFlag==true)
                      {
                          Application.application.unloadModule();
                      }
                  }
             
                  private function handleUpdateStationDetailsFault(event:FaultEvent):void
                  {
                      var errorMessage:ErrorMessage = event.message as ErrorMessage;
                      Alert.show(errorMessage.rootCause.message);
                  }
                 
                  private function onSearch():void
                  {
                      if(txtName.text=="" || txtName.text==null)
                      {
                          Alert.show("Enter a name for search");
                          return;
                      }
                      if((txtName.text).length < 4)
                      {
                          Alert.show("Search should contain more than 3 alphabets");
                          return;
                      }
                      var d:String = txtName.text;
                      branch = CitizenApplication.initInfo.registeredUser.branchDetails.bdBranchNo;
                      uniqueIdMasterUCFlexRO.readByCustomerName(d,branch);
                      showLoading();
                  }
                 
                  private function handleReadByCustomerNameResult(event:ResultEvent):void                //In handle if record does not exists, dsiplays error message and resets the field
                  {
                      customerDetails =ArrayCollection(event.result);
                      PopUpManager.removePopUp(_progBar);
                      if(customerDetails.length==0)
                      {
                          Alert.show("Record Not Found, Enter Proper Name ");
                          onReset();
                      }
                  }   
                         
                  private function handleReadByCustomerNameFault(event:FaultEvent):void
                  {
                      Alert.show(event.fault.faultDetail + " -- " + event.fault.faultString + "handleReadByCustomerNameFault");
                  }
                 
                  private function onReset():void
                  {
                      customerDetails=new ArrayCollection();
                      txtName.text="";
                  }
                 
                  private function onCancel():void
                  {
                      utilityUCFlexRO.updateStationDetails("MM0001");
                      moduleCloseFlag=true;
                  }
                 
                  private function btnBackClick():void
                  {
                      view1.selectedIndex=0;
                  }
                 
                  private function btnBackClick1():void
                  {
                      view1.selectedIndex=1;
                  }
                 
                  private function onItemClick( e:ListEvent ):void
                  {
                      if(dgCustDetails.selectedItem == null)
                      {
                          Alert.show("Select Proper Record");
                      }
                      else
                      {
                          lblId.text = e.itemRenderer.data.uimCustomerId;
                          lblName.text = e.itemRenderer.data.uimCustomerName;
                          var custId:int = Number(lblId.text);   
                          uniqueIdMasterUCFlexRO.getCustomerAcDetails(custId,branch);
                          showLoading();           
                      }
                  }
                 
                  private function handlegetCustomerAcDetailsResult(event:ResultEvent):void               
                  {
                      //XMLDocument = event.result as XML;
                      acDetails = new XMLList(event.result.menu);
                      //Alert.show("Name: "+event.result.@name);
                      PopUpManager.removePopUp(_progBar);
                      view1.selectedIndex=1;
                      //adg1.dataProvider=acDetails;
                  }   
                         
                  private function handlegetCustomerAcDetailsFault(event:FaultEvent):void
                  {
                      PopUpManager.removePopUp(_progBar);
                      Alert.show(event.fault.faultDetail + " -- " + event.fault.faultString + "handlegetCustomerAcDetailsFault");
                  }
                 
              ]]>
          </mx:Script>

       

          <mx:ViewStack height="688" width="856" id="view1">
              <mx:Canvas>
                  <mx:Panel x="51" y="25" width="754" height="550" layout="absolute" title="Customer Search Page">
                      <mx:HBox x="174" y="26" horizontalAlign="center" verticalAlign="middle">
                          <mx:Label text="Enter Name:"/>
                          <mx:TextInput id="txtName" width="228"/>
                          <mx:LinkButton label="Search" click="onSearch()"/>
                      </mx:HBox>
                      <mx:Label text="--" id="lblId" x="40" y="194"/>
                      <mx:Label text="--" id="lblName" x="40" y="226"/>
                      <mx:DataGrid dataProvider="{customerDetails}" id="dgCustDetails" allowMultipleSelection="false" editable="false"
                          showHeaders="true" draggableColumns="false" width="718" height="373" itemClick="onItemClick(event);" x="10" y="61">
                          <mx:columns>
                              <mx:DataGridColumn headerText="Customer Id" dataField="uimCustomerId" width="150"/>
                              <mx:DataGridColumn headerText="Customer Name" dataField="uimCustomerName"/>
                          </mx:columns>
                      </mx:DataGrid>
                      <mx:ControlBar>
                          <mx:Button label="CANCEL" click="onCancel()" width="80"/>
                          <mx:Button label="RESET" click="onReset()" width="80"/>
                      </mx:ControlBar>
                  </mx:Panel>
              </mx:Canvas>
              <mx:Canvas>
                  <mx:TitleWindow x="10" y="10" width="836" height="421" layout="absolute">
                      <mx:AdvancedDataGrid x="6.5" y="10" id="adg1" designViewDataType="tree" variableRowHeight="true" width="807" height="278" fontSize="14">
                          <mx:dataProvider>
                                <mx:HierarchicalData source="{acDetails}"/>
                          </mx:dataProvider>
                         
                          <mx:groupedColumns>
                              <mx:AdvancedDataGridColumn headerText="Type Of A/c" dataField="@Name" width="150"/>
                              <mx:AdvancedDataGridColumn headerText="Details Of A/c"/>
                          </mx:groupedColumns>
                         
                          <mx:rendererProviders>
                              <mx:AdvancedDataGridRendererProvider id="adgpr1" depth="2" columnIndex="1" renderer="AcDetails1" columnSpan="0"/>
                          </mx:rendererProviders>
                         
                      </mx:AdvancedDataGrid>
                      <mx:ControlBar height="56" y="335">
                          <mx:Button label="BACK" width="80" click="btnBackClick()"/>
                          <mx:Spacer width="100%"/>
                          <mx:Button label="EXIT" click="onCancel()" width="80"/>
                      </mx:ControlBar>
                  </mx:TitleWindow>
              </mx:Canvas>
          </mx:ViewStack>
      </mx:Module>

       

       

       

      XML File Generated In JAVA:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <menu>
      <AcType Name="Savings">
      <SavingAcDetails AcName="Mr. MELROY BENT" AccountNo="4" ClearBalance="744.18" ProductID="SB" TotalBalance="744.18">
      <SavingMoreAcDetails AcStatus="OPERATIVE" AcType="NORMAL" FreezeCode="No Freeze" ModeOfOper="AnyOne Single Or Survivor"/>
      </SavingAcDetails>
      </AcType>
      <AcType Name="TermDeposit">
      <TDAcDetails AcName="Mr. BENT MELROY" AccountNo="1731" ProductID="TD">
      <TDMoreAcDetails AcStatus="OPERATIVE" AcType="NORMAL" FreezeCode="No Freeze" ModeOfOper="Either or Survivor"/>
      </TDAcDetails>
      <TDAcDetails AcName="Mr. BENT MELROY" AccountNo="2287" ProductID="TD">
      <TDMoreAcDetails AcStatus="NEW" AcType="NORMAL" FreezeCode="No Freeze" ModeOfOper="Self"/>
      </TDAcDetails>
      <TDAcDetails AcName="Mr. BENT MELROY" AccountNo="78" ProductID="TD">
      <TDMoreAcDetails AcStatus="OPERATIVE" AcType="NORMAL" FreezeCode="No Freeze" ModeOfOper="Self"/>
      </TDAcDetails>
      </AcType>
      </menu>

       

       

       

      Tried Alot Of Examples Online But In Vain....

      Need Help....

      Thanks In Advance....