6 Replies Latest reply on Dec 21, 2010 8:29 AM by saisri2k2

    Data Not Loading ??

    Whitetimer Level 1

      Hi All

       

      I am trying to build a shopping cart and i am having problems reading the xml file.

       

      This is the xml file structure

       

      <shop SelectedCategoryID = '0'>
          <category id='0' name='Category 1'>
              <shopitem id='0001' name='' description='' image='' price='' />
              <shopitem id='0002' name='' description='' image='' price='' />
              <shopitem id='0003' name='' description='' image='' price='' />
              <shopitem id='0004' name='' description='' image='' price='' />
          </category>
          <category id='1' name='Category 2'>
              <shopitem id='1001' name='' description='' image='' price='' />
              <shopitem id='1002' name='' description='' image='' price='' />
              <shopitem id='1003' name='' description='' image='' price='' />
              <shopitem id='1004' name='' description='' image='' price='' />
          </category>
          <category id='2' name='Category 3'>
              <shopitem id='2001' name='' description='' image='' price='' />
              <shopitem id='2002' name='' description='' image='' price='' />
              <shopitem id='2003' name='' description='' image='' price='' />
              <shopitem id='2004' name='' description='' image='' price='' />
          </category>
          <category id='3' name='Category 4'>
              <shopitem id='3001' name='' description='' image='' price='' />
              <shopitem id='3002' name='' description='' image='' price='' />
              <shopitem id='3003' name='' description='' image='' price='' />
              <shopitem id='3004' name='' description='' image='' price='' />
          </category>
      </shop>
      

       

      This is my ValueObject

       

      package ShoppingCart.ValueObject
      {
      
          [Bindable]
          public class ProductVO
          {
      
              // PRODUCT VARIABLES
              public var productID:int;
              public var productName:String;
              public var productDescription:String;
              public var productImage:String;
              public var productPrice:Number;
      
              public function ProductVO(productID:int,productName:String,productDescription:String,productImage:String,productPrice:Number)
              {
                  this.productID = productID;
                  this.productName = productName;
                  this.productDescription = productDescription;
                  this.productImage = productImage;
                  this.productPrice = productPrice;
              }
      
              public function toString():String
              {
                  return '[ProductVO]' + this.productName;
              }
      
              public static function buildProduct( obj:Object ):ProductVO
              {
                  var prod:ProductVO;
      
                  prod = new ProductVO( obj.productID,obj.productName,obj.productDescription,obj.productImage,obj.productPrice );
      
                  return prod;
              }
      
              public static function buildProductsFromAttributes( data:XML ):ProductVO
              {
                  var prod:ProductVO;
      
                  prod = new ProductVO( data.@productID,data.@productName,data.@productDescription,data.@productImage,data.@productPrice );
      
                  return prod;
              }
          }
      }
      
      

       

      This is where calling the data and displaying the result

       

      <s:Group
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:mx="library://ns.adobe.com/flex/mx"
              xmlns:ShopView='ShoppingCart.Views.*'
              width="900" height="100%"
              creationComplete="init()">
      
          <!-- Properties of the parent ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
          <s:layout>
              <s:VerticalLayout verticalAlign="middle" horizontalAlign="center" />
          </s:layout>
      
          <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
          <fx:Declarations>
      
              <s:HTTPService id="productService" url="ShoppingCart/Data/ShopData1.xml" resultFormat="e4x" result="productServiceResultHandler(event)" />
          </fx:Declarations>
          <!-- Metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <fx:Script>
              <![CDATA[
      
      
              // import statements ----------------------------------------
              import ShoppingCart.ValueObject.ProductVO;
              import mx.collections.ArrayCollection;
              import mx.rpc.events.ResultEvent;
      
              // variable declarations ------------------------------------
              [Bindable]
              public var products:Array = new Array();
              [Bindable]
              public var resultData:XMLList = new XMLList();
              [Bindable]
              public var productInventory:ArrayCollection;
      
              // getter/setters -------------------------------------------
      
              // helper methods -------------------------------------------
      
              // event handlers -------------------------------------------
              private function init():void
              {
                  productService.send();
              }
      
              private function productServiceResultHandler(event:ResultEvent):void
              {
                  resultData = event.result.shop.shopitem;
      
                  for each ( var prod:XML in resultData )
                  {
                      var product:ProductVO = ProductVO.buildProductsFromAttributes( prod );
                      products.push( product );
                  }
      
                  productInventory = new ArrayCollection( products );
              }
      
              
              ]]>
          </fx:Script>
      
          <!-- States ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
      
          <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
          <mx:ApplicationControlBar width="900" height="50" horizontalAlign="center" verticalAlign="middle">
      
              <s:Label id="controlBarLabel" width="150" />
              <s:DropDownList width="200" />
      
          </mx:ApplicationControlBar>
      
          <s:HGroup width="100%" height="100%">
      
              <mx:DataGrid width="100%" height="100%" dataProvider="{productInventory}">
                  <mx:columns>
                      <mx:DataGridColumn width="100" headerText="Product #" dataField="productID" />
                      <mx:DataGridColumn headerText="Product Name" dataField="productName" />
                      <mx:DataGridColumn width="150" headerText="Price £" dataField="productPrice" />
                  </mx:columns>
              </mx:DataGrid>
      
              <ShopView:CartView id="shoppingCartCheckoutView" />
          </s:HGroup>
      
      </s:Group>
      

       

      Any thoughts please ?

       

      Many Thanks