4 Replies Latest reply on Sep 7, 2008 5:25 AM by Newsgroup_User

    Trying to find childnode attributes using nested loops ...

    zakel
      This should be easy. See comment in Combobox code where I try a nested loop to get child nodes attributes.

      I have a dynamic xml driven form that I am trying to get the "label"
      and "value" using nested for loops for the combobox. I am using
      "droplabel" attribute. The xml schema is final, I cannot change this.

      I am having problem targeting the child node attributes.

      I keep running into error: "A term is undefined and has no
      properties." I am sure I am not properly formatting the for loop
      statement.

      ---------------------------------------------------------------
      XML:

      <?xml version="1.0" encoding="utf-8?>

      <formdata userid="davis" fname="David" lname="washingon" auth="1">

      <element position="1" questionlabel="What is todays time ?">
      <item id="1" inputtype="TextInput">Monday</item>
      <item id="222" inputtype="TextInput">tonday</item>
      </element>


      <element position="5" questionlabel="What is your time of arrival ?">
      <item id="5" inputtype="ComboBox">
      <drop droplabel="Select Answer---" dropvalue="0"></drop>
      <drop droplabel="What is this" dropvalue="1" selected="true"></drop>
      <drop droplabel="What is that" dropvalue="2"></drop>
      </item>
      </element>


      </formdata>

      ----------------------------------------------------------------------

      Flex Code:


      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      backgroundGradientColors="white" backgroundDisabledColor="white"
      backgroundColor="white" layout="absolute" horizontalAlign="center"
      creationComplete="handleCreationComplete()"
      verticalScrollPolicy="auto" cachePolicy="off">

      <mx:Script>
      <![CDATA[
      import mx.controls.Text;
      import mx.containers.FormItem;
      import mx.controls.Label;
      import mx.controls.Button;
      import mx.containers.ControlBar;
      import mx.controls.TextInput;
      import mx.controls.RadioButtonGroup;
      import mx.controls.List;
      import mx.controls.ComboBox;
      import mx.controls.CheckBox;
      import mx.controls.FormItemLabel;
      import mx.controls.RadioButton;
      import mx.controls.TextArea;
      import mx.controls.Alert;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      import mx.controls.ComboBox;
      import mx.collections.ArrayCollection;
      import mx.controls.DateField;
      import mx.core.IUIComponent;
      import mx.core.IUITextField;
      import mx.utils.ObjectUtil;
      import flash.utils.*;


      private function handleCreationComplete():void
      {

      XMLService.send();

      }

      private function errorHandler(evt:FaultEvent):void
      {
      Alert.show("Error: " + evt.fault.message);
      }

      private function resultHandler(evt:ResultEvent):void
      {

      buildForm(new XML(evt.result));
      }

      private function buildForm(xml:XML):void
      {
      var lst:XMLList = xml.children();
      var lsta:XMLList = xml.element.item.children();



      for(var i:int = 0; i < lst.length(); i++)
      {
      var x:XMLList = lst .children();





      for(var j:int = 0; j < x.length(); j++)
      {
      if(x[j].@inputtype == 'TextInput')
      {
      var frmItem:FormItem = new FormItem();
      frmItem.direction = "vertical";


      var tb:TextInput = new TextInput();
      tb.text = x[j];
      tb.id = x[j].@id;
      tb.toolTip = 'Enter your Answer here';
      frmItem.addChild(tb);

      userInfoForm.addChild(frmItem);

      }

      else
      {
      // Support other form field types


      if(x[j].@inputtype == 'ComboBox')
      {


      // Having problem with this nested loop.


      for(var d:int = 0; d < lsta.length(); d++)

      var p:XMLList = lsta[d].children();

      for(var r:int = 0; r < p.length(); r++)



      var frmItemCombo:FormItem = new FormItem();



      var tg:ComboBox = new ComboBox();


      tg.alpha = .5;
      tg.text = p[r].@droplabel;
      tg.width = 230;
      tg.id = x[j].@id;
      frmItemCombo.required = true;
      tg.data = x[j].@label;


      frmItemCombo.addChild(tg);

      userInfoForm.addChild(frmItemCombo);



      }
      }
      }
      }


      }
      ]]>
      </mx:Script>
      <mx:HTTPService fault="errorHandler(event)" id="XMLService"
      resultFormat="e4x" url="test/formdata_final_a.xml"
      result="resultHandler(event)" method="POST" />

      <mx:Panel title="XML Driven Form -- Send Receive Data from SOA _JSP"
      height="90%" width="70%"
      paddingTop="50" paddingBottom="10" paddingLeft="50"
      paddingRight="10" layout="vertical" horizontalAlign="left"
      verticalAlign="top" backgroundColor="#EEEFFD" borderColor="#E2E2E2"
      x="72.5" y="10">
      <mx:Form id="userInfoForm" borderThickness="1"
      borderColor="#FCFAFA" borderStyle="solid" width="90%"/>
      </mx:Panel>

      </mx:Application>
        • 1. Re: Trying to find childnode attributes using nested loops ...
          Level 7

          "zakel" <webforumsuser@macromedia.com> wrote in message
          news:g9usnd$1du$1@forums.macromedia.com...
          > This should be easy. See comment in Combobox code where I try a nested
          > loop to
          > get child nodes attributes.
          >
          > I have a dynamic xml driven form that I am trying to get the "label"
          > and "value" using nested for loops for the combobox. I am using
          > "droplabel" attribute. The xml schema is final, I cannot change this.
          >
          > I am having problem targeting the child node attributes.
          >
          > I keep running into error: "A term is undefined and has no
          > properties." I am sure I am not properly formatting the for loop
          > statement.
          >
          > ---------------------------------------------------------------
          > XML:
          >
          > <?xml version="1.0" encoding="utf-8?>
          >
          > <formdata userid="davis" fname="David" lname="washingon" auth="1">
          >
          > <element position="1" questionlabel="What is todays time ?">
          > <item id="1" inputtype="TextInput">Monday</item>
          > <item id="222" inputtype="TextInput">tonday</item>
          > </element>
          >
          >
          > <element position="5" questionlabel="What is your time of arrival ?">
          > <item id="5" inputtype="ComboBox">
          > <drop droplabel="Select Answer---" dropvalue="0"></drop>
          > <drop droplabel="What is this" dropvalue="1" selected="true"></drop>
          > <drop droplabel="What is that" dropvalue="2"></drop>
          > </item>
          > </element>
          >
          >
          > </formdata>
          >
          > ----------------------------------------------------------------------
          >
          > Flex Code:
          >
          >
          > <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          > backgroundGradientColors="white" backgroundDisabledColor="white"
          > backgroundColor="white" layout="absolute" horizontalAlign="center"
          > creationComplete="handleCreationComplete()"
          > verticalScrollPolicy="auto" cachePolicy="off">
          >
          > <mx:Script>
          > <![CDATA[
          > import mx.controls.Text;
          > import mx.containers.FormItem;
          > import mx.controls.Label;
          > import mx.controls.Button;
          > import mx.containers.ControlBar;
          > import mx.controls.TextInput;
          > import mx.controls.RadioButtonGroup;
          > import mx.controls.List;
          > import mx.controls.ComboBox;
          > import mx.controls.CheckBox;
          > import mx.controls.FormItemLabel;
          > import mx.controls.RadioButton;
          > import mx.controls.TextArea;
          > import mx.controls.Alert;
          > import mx.rpc.events.FaultEvent;
          > import mx.rpc.events.ResultEvent;
          > import mx.controls.ComboBox;
          > import mx.collections.ArrayCollection;
          > import mx.controls.DateField;
          > import mx.core.IUIComponent;
          > import mx.core.IUITextField;
          > import mx.utils.ObjectUtil;
          > import flash.utils.*;
          >
          >
          > private function handleCreationComplete():void
          > {
          >
          > XMLService.send();
          >
          > }
          >
          > private function errorHandler(evt:FaultEvent):void
          > {
          > Alert.show("Error: " + evt.fault.message);
          > }
          >
          > private function resultHandler(evt:ResultEvent):void
          > {
          >
          > buildForm(new XML(evt.result));
          > }
          >
          > private function buildForm(xml:XML):void
          > {
          > var lst:XMLList = xml.children();
          > var lsta:XMLList = xml.element.item.children();
          >
          >
          >
          > for(var i:int = 0; i < lst.length(); i++)
          > {
          > var x:XMLList = lst .children();
          >
          >
          >
          >
          >
          > for(var j:int = 0; j < x.length(); j++)
          > {
          > if(x[j].@inputtype == 'TextInput')
          > {
          > var frmItem:FormItem = new FormItem();
          > frmItem.direction = "vertical";
          >
          >
          > var tb:TextInput = new TextInput();
          > tb.text = x[j];
          > tb.id = x[j].@id;
          > tb.toolTip = 'Enter your Answer here';
          > frmItem.addChild(tb);
          >
          > userInfoForm.addChild(frmItem);
          >
          > }
          >
          > else
          > {
          > // Support other form field types
          >
          >
          > if(x[j].@inputtype == 'ComboBox')
          > {
          >
          >
          > // Having problem with this nested loop.
          >
          >
          > for(var d:int = 0; d < lsta.length(); d++)
          >
          > var p:XMLList = lsta[d].children();
          >
          > for(var r:int = 0; r < p.length(); r++)


          You don't need a loop. Just set your ComboBox's dataProvider to
          x
          .child('drop') and set its labelField to 'dropLabel'.

          HTH;

          Amy


          • 2. Re: Trying to find childnode attributes using nested loops ...
            zakel Level 1
            Amy Thanks so much for your help!

            I've tried this several ways. I think I am doing something wrong. One good thing, x.child(' drop') goes to the children. I just cannot seem to get the labelField to show the attribute 'droplabel'

            This is what I did below.



            var frmItemCombo:FormItem = new FormItem();
            var tg:ComboBox = new ComboBox();
            tg.alpha = .9;
            tg.dataProvider = x.child('drop');
            tg.labelField = 'droplabel';
            tg.width = 230;
            frmItemCombo.required = true;
            frmItemCombo.addChild(tg);
            userInfoForm.addChild(frmItemCombo);
            varlabelx.text = x.child('drop');
            • 3. Re: Trying to find childnode attributes using nested loops ...
              zakel Level 1
              Amy, Thanks to you I got it working.

              This is what I did wrong: tg.labelField = 'droplabel';
              This is correct: tg.labelField = "@droplabel";
              • 4. Re: Trying to find childnode attributes using nested loops ...
                Level 7

                "zakel" <webforumsuser@macromedia.com> wrote in message
                news:ga0gmm$nft$1@forums.macromedia.com...
                > Amy Thanks so much for your help!
                >
                > I've tried this several ways. I think I am doing something wrong. One good
                > thing, x.child(' drop') goes to the children. I just cannot seem to get
                > the
                > labelField to show the attribute 'droplabel'

                Oops, sorry...use '@dropLabel'

                HTH;

                Amy