3 Replies Latest reply on May 9, 2007 2:32 PM by skarkar

    list item using xml from a django view

    skarkar

      I'm using django to deliver xml files from a postgres db. I login by using a HTTPService. I am not able to get the xml to provide data to a List item.

      The mxml app is below:

      quote:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute">

      <mx:Script>
      <![CDATA[
      import mx.events.MenuEvent;
      import mx.collections.ArrayCollection;
      import mx.collections.XMLListCollection;
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;


      [Bindable]
      private var mails:XMLListCollection = new XMLListCollection();
      [Bindable]
      private var units:ArrayCollection = new ArrayCollection();

      private function handleLoginClicked(event:MouseEvent):void {
      svcAccountLogin.send({username: "admin", password: "admin"});
      }

      private function handleLoginResult(event:ResultEvent):void {

      //trace(event);
      trace(event.result);
      mails=event.result.allMails.mail;
      //units=event.result.allUnits.unit;

      }
      ]]>
      </mx:Script>

      <mx:HTTPService
      id="svcAccountLogin"
      url=" http://192.168.1.100:8080/accounts/login/?next=/maillog/"
      method="POST"
      resultFormat="xml"
      result="handleLoginResult(event)"/>


      <mx:VBox x="76" y="62" height="100%" id="loginUserPass" label="Enter Username, password here">

      <mx:Button id="submitLoginBtn" label="Login" click="handleLoginClicked(event)"/>

      <mx:List id="mailId"
      rowCount="1"
      dataProvider="{mails}"
      labelField="mailFrom">

      </mx:List>
      </mx:VBox>

      </mx:Application>


      The console shows the following output:

      quote:

      <allMails><mail><mailId>171467</mailId><mailFrom>user@domain.com</mailFrom></mail></allMa ils>
      ReferenceError: Error #1069: Property allMails not found on flash.xml.XMLNode and there is no default value.


      Anyone with info on this let me know of a way to make this work.
        • 1. Re: list item using xml from a django view
          ntsiii Level 3
          var xmlResult:XML = XML(event.result);
          var xlResult:XMLList = xmlResult.allMails.mail;
          mails=new XMLListCollection()xlResult;

          trace using toXMLString between those steps to make sure you are getting the correct data.

          Tracy
          • 2. Re: list item using xml from a django view
            ntsiii Level 3
            Mistake in the last line, should be:
            mails=new XMLListCollection(xlResult);
            • 3. list item using xml from a django view
              skarkar Level 1
              Thanks for your answer. I was along the same lines :)

              I deleted the "xml" result format. Also changed back to arraycollection type of getting the result from the result event. These changes were enough to make it work.

              I've some more questions:

              1) If no resultFormat is set, what's the default type?
              2) What's the advantage of getting the result as e4x/xml, is it the descendant accessor syntax, that's easy to use?
              3)I need to login into the XML RPC server, before starting to poll it for periodical updates. Can I use https in the HTTPService instead of HTTP in its URL?

              The following worked finally:

              quote:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application
              xmlns:mx=" http://www.adobe.com/2006/mxml"
              layout="absolute">

              <mx:Script>
              <![CDATA[
              import mx.events.MenuEvent;
              import mx.collections.ArrayCollection;
              import mx.collections.XMLListCollection;
              import mx.rpc.events.ResultEvent;
              import mx.controls.Alert;
              import mx.rpc.http.HTTPService;


              [Bindable]
              //private var mails1:ArrayCollection = new ArrayCollection();
              private var mails:XMLListCollection= new XMLListCollection();

              [Bindable]
              private var units:ArrayCollection = new ArrayCollection();

              private function handleLoginClicked(event:MouseEvent):void {
              svcAccountLogin.send({username: "admin", password: "admin"});
              }

              private function handleLoginResult(event:ResultEvent):void {

              //trace(event);
              //trace("full result");
              //trace(event.result);
              try{
              units = event.result.allMails.mail;
              trace("Mails in array collection:\n"+units.toString());
              }
              catch(error:Error){
              trace("Error converting mails to arraycollection:"+error);
              }
              try{
              //mails = new XMLListCollection(event.result.allMails);
              var xmlresult:XML = new XML(event.result);
              var xllist:XMLList = xmlresult.allMails.mail;
              mails = new XMLListCollection(xllist);
              trace("Created mails array/xmlllistcollection!!!");
              }
              catch(error:Error){
              trace("Error in creating mails array/xmlllistcollection:" + error);
              }

              //units=event.result.allUnits.unit;

              }
              // resultFormat="xml"
              // "POST"
              // useProxy="false"
              // <mx:List id="mailId"
              // rowCount="1"
              // dataProvider="{mails}"
              // labelField="mailFrom">
              // </mx:List>

              ]]>
              </mx:Script>

              <mx:HTTPService
              id="svcAccountLogin"
              url=" http://192.168.1.100:8080/accounts/login/?next=/maillog/"
              method="POST"
              result="handleLoginResult(event)"/>


              <mx:VBox x="76" y="62" height="100%" id="loginUserPass" label="Enter Username, password here">

              <mx:Button id="submitLoginBtn" label="Login" click="handleLoginClicked(event)"/>

              <mx:List id="mailId"
              dataProvider="{units}"
              labelField="mailFrom">
              </mx:List>


              </mx:VBox>

              </mx:Application>