0 Replies Latest reply on Jul 21, 2011 5:03 PM by RIA with Flash Builder

    How to search XML data from a HTTPMultiService and display the result on the Spark List

    RIA with Flash Builder

      Hello all,

       

      I am totally new to Flash Builder and Actionscript and hope someone might be able to help me out. I basically create a mobile app with a single view. The view has a TextInput as a search box and a search button. I conntected a Data/Service using a local XML file and bind the Data to a Spark List. Innitally the List will show nothing until the user enter the search term and hit the button. The List suppose to show the XML data that match the search term.

       

      Now is my problem. I cannot make the List to show the data that match the search text. The List just shows ALL the data.

       

      Here are my MXML code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:shopping="services.shopping.*"
              title="Search">
          <fx:Script>
              <![CDATA[
                  import mx.events.FlexEvent;
                 
                  protected function button1_clickHandler(event:MouseEvent):void
                  {
                      navigator.popView();
                  }
                 
                  protected function list_creationCompleteHandler(event:FlexEvent):void
                  {
                      getDataResult.token = shopping.getData();
                  }
                 
                  protected function seach_clickHandler(event:MouseEvent):void
                  {
                      getDataResult.token = shopping.getSearchData(searchTxt.text);
                  }
                 
              ]]>
          </fx:Script>
          <fx:Declarations>
              <s:CallResponder id="getDataResult"/>
              <shopping:Shopping id="shopping"/>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <s:actionContent>
              <s:Button height="79" label="Back" click="button1_clickHandler(event)"/>
          </s:actionContent>
          <s:List id="list" left="0" right="0" top="111" bottom="0"
                  creationComplete="list_creationCompleteHandler(event)" labelField="english">
              <s:AsyncListView list="{getDataResult.lastResult}"/>
          </s:List>
          <s:TextInput id="searchTxt" x="80" y="34" width="250" height="49" enabled="true"
                       prompt="search..."/>
          <s:Button id="search" x="338" y="35" width="72" height="49" label="s"
                    click="seach_clickHandler(event)"/>
      </s:View>

       

      Here is the _Super_Shopping.as file:

       

      /**
      * This is a generated class and is not intended for modification.  To customize behavior
      * of this service wrapper you may modify the generated sub-class of this class - Shopping.as.
      */
      package services.shopping
      {
      import com.adobe.fiber.core.model_internal;
      import com.adobe.fiber.services.wrapper.HTTPServiceWrapper;
      import com.adobe.serializers.xml.XMLSerializationFilter;

       

      import mx.rpc.AbstractOperation;
      import mx.rpc.AsyncToken;
      import mx.rpc.http.HTTPMultiService;
      import mx.rpc.http.Operation;

       

      import valueObjects.Shop;

       

      [ExcludeClass]
      internal class _Super_Shopping extends com.adobe.fiber.services.wrapper.HTTPServiceWrapper
      {
          private static var serializer0:XMLSerializationFilter = new XMLSerializationFilter();

       

          // Constructor
          public function _Super_Shopping()
          {
              // initialize service control
              _serviceControl = new mx.rpc.http.HTTPMultiService();
               var operations:Array = new Array();
               var operation:mx.rpc.http.Operation;
               var argsArray:Array;

       

               operation = new mx.rpc.http.Operation(null, "getData");
               operation.url = "assets/data/shopping.xml";
               operation.method = "GET";
               operation.serializationFilter = serializer0;
               operation.properties = new Object();
               operation.properties["xPath"] = "/::shop";
               operation.resultElementType = valueObjects.Shop;
               operations.push(operation);
              
               operation = new mx.rpc.http.Operation(null, "getSearchData");
               operation.url = "assets/data/shopping.xml";
               operation.method = "GET";
               operation.resultFormat = "text";
               argsArray = new Array("item");
               operation.argumentNames = argsArray;
               operation.properties = new Object();
               operation.properties["xPath"] = "/::shop";
               operation.resultElementType = valueObjects.Shop;
               operations.push(operation);

       

               _serviceControl.operationList = operations;

       


               preInitializeService();
               model_internal::initialize();
          }
         
          //init initialization routine here, child class to override
          protected function preInitializeService():void
          {
           
          }

       

          /**
            * This method is a generated wrapper used to call the 'getData' operation. It returns an mx.rpc.AsyncToken whose
            * result property will be populated with the result of the operation when the server response is received.
            * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value.
            * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events.
            *
            * @see mx.rpc.AsyncToken
            * @see mx.rpc.CallResponder
            *
            * @return an mx.rpc.AsyncToken whose result property will be populated with the result of the operation when the server response is received.
            */
          public function getData() : mx.rpc.AsyncToken
          {
              var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getData");
              var _internal_token:mx.rpc.AsyncToken = _internal_operation.send() ;
              return _internal_token;
          }
         
          public function getSearchData(item:String) : mx.rpc.AsyncToken
          {
              var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getSearchData");
              var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(item);
              return _internal_token;
          }
          
      }

       

      }

       

      The getSearchData() supposed to return XML data that match the search text, but it doesn't. Can anyoen help?

       

      Thank you!