5 Replies Latest reply on Feb 26, 2008 1:35 AM by khanhnd

    Help needed: HTTPService, XML, Repeater

    rkoe123
      Hi there
      I am very much new to Flex 2 technology and require help regarding HTTPService and XML.
      In my main application (NestedRepeater.mxml), I have the following code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:comps="component.*" layout="absolute" creationComplete="userRequest.send()">
      <mx:HTTPService id="userRequest" url="/Users/ronnyk/Sites/book.xml" useProxy="false" method="POST" />
      <mx:VBox>
      <mx:Repeater id="Repeater1" dataProvider="{userRequest.lastResult.book.section}">
      <comps:Section sectionNumber="{Repeater1.currentItem.sectionnumber}" xmlSection="{Repeater1.currentItem}" />
      </mx:Repeater>
      </mx:VBox>
      </mx:Application>

      In my real app, I have a PHP script as the url for the HTTPService, but for the sake of simplicity, I'll just use book.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <book>
      <section>
      <sectionnumber>s1</sectionnumber>
      <chapter>
      <chapternumber>c1</chapternumber>
      </chapter>
      <chapter>
      <chapternumber>c2</chapternumber>
      </chapter>
      </section>
      <section>
      <sectionnumber>s2</sectionnumber>
      <chapter>
      <chapternumber>c3</chapternumber>
      </chapter>
      </section>
      </book>

      As you can see as well, I have a custom component called Section.mxml within the repeater of the main app, the custom component is as follows:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml">
      <mx:Script>
      <![CDATA[
      [Bindable]
      public var xmlSection:XML;
      [Bindable]
      public var sectionNumber:String;
      ]]>
      </mx:Script>
      <mx:VBox>
      <mx:Panel id="panel1" layout="absolute" title="Section" width="166" height="70">
      <mx:VBox>
      <mx:Label text="{this.sectionNumber}"/>
      </mx:VBox>
      </mx:Panel>
      <mx:Repeater id="Repeater2" dataProvider="{xmlSection.chapter}">
      <mx:Panel layout="absolute" title="Chapter" height="100" width="166">
      <mx:Label text="{Repeater2.currentItem.chapternumber}" />
      </mx:Panel>
      </mx:Repeater>
      </mx:VBox>
      </mx:Canvas>

      I am passing xmlSection="{Repeater1.currentItem}" to the custom component so that I can correctly create nested children for each parent. But anyway, my problem happens when I include xmlSection="{Repeater1.currentItem}" to the custom Section component, it always displays only one section (the label "s1" doesn't even appear), but if I exclude xmlSection="{Repeater1.currentItem}", when I run it, it displays correctly:
      s1
      s2

      Any help/suggestion would be greatly appreciated as I am at my wits end regarding my project.
      Let me know if you need any more info.

      Thanks!
        • 1. Re: Help needed: HTTPService, XML, Repeater
          rkoe123 Level 1
          Hi again,
          Based on the XML I provided, the final result I want is:
          s1
          c1
          c2
          s2
          c3

          But if anyone can tell me what went wrong when i included xmlSection="{Repeater1.currentItem}", so that it can show:
          s1
          s2

          would be useful.
          But I guess I have to solve this first, in order to get the final result.
          • 2. Re: Help needed: HTTPService, XML, Repeater
            rkoe123 Level 1
            Hi again,
            After going through the HTTPService topic forum, I should be using resultHandler for my HTTPService, so I change my main mxml app into:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:comps="component.*" layout="absolute" creationComplete="userRequest.send()">

            <mx:Script>
            <![CDATA[
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var myData:XML;

            private function resultHandler(event:ResultEvent):void {
            myData = event.result.book.section as XML;
            }
            ]]>
            </mx:Script>
            <mx:HTTPService id="userRequest" url="/Users/ronnyk/Sites/book.xml" resultFormat="e4x" result="resultHandler(event)" useProxy="false" method="POST" />
            <mx:VBox>
            <mx:Repeater id="Repeater1" dataProvider="{myData}">
            <comps:Section sectionNumber="{Repeater1.currentItem.sectionnumber}" xmlSection="{Repeater1.currentItem}" />
            </mx:Repeater>
            </mx:VBox>
            </mx:Application>

            But now, when I run it, it displays nothing, just a blank browser. Can someone please help? Maybe because I shouldn't use creationComplete="userRequest.send()" in the Application tag?

            Thanks!
            • 3. Re: Help needed: HTTPService, XML, Repeater
              rkoe123 Level 1
              Got it!!
              the result handler should be:
              private function resultHandler(event:ResultEvent):void {
              myData = XML(event.result);
              }

              and the repeater data provider should be:
              dataProvider="{myData.section}"
              • 4. Re: Help needed: HTTPService, XML, Repeater
                khanhnd
                Hi all!
                I have same problem.
                Here my xml data:

                <DataSet>
                <READTAB>
                <A>1</A>
                <B>hello</B>
                </READTAB>
                <READTAB>
                <A>2</A>
                <B>world</B>
                </READTAB>
                <READTAB>
                <A>19</A>
                <B>XIN CHAOF NHE</B>
                </READTAB>
                </DataSet>
                I do follow ur guide but when i bind:
                <mx:Repeater id="Repeater1" dataProvider="{myData.READTAB}">
                <mx:Label text="{Repeater1.currentItem}"/>
                </mx:Repeater>

                then it display:
                <READTAB>
                <A>19</A>
                <B>XIN CHAOF NHE</B>
                </READTAB>

                Help me!
                Thanks
                • 5. Re: Help needed: HTTPService, XML, Repeater
                  khanhnd Level 1
                  my purpose display field B in Lable, how to do

                  Thanks!