4 Replies Latest reply on Apr 5, 2007 2:28 PM by Jinglesthula

    Radio Button binding to XML

    Jinglesthula Level 1
      Based on the examples here and here I have a datagrid which uses an XML object as its dataprovider. The xml goes like this:

      <questions>
      <question>
      <prompt>What are your heroes?</prompt>
      <answers>
      <answer>
      <correct>true</correct>
      <text>Luther Higgs</text>
      </answer>
      <answer>
      <correct>false</correct>
      <text>Barney Fife</text>
      </answer>
      </answers>
      </question>
      </questions>

      Well formed (if a bit confusing) xml. In my datagrid I have two columns. The second column binds to questions.question.answers.answer.text and works just fine. The datagrid's editable property is set to true, and I'm able to click on the second colum and type and it saves the answer back into the xml object just fine. The problem lies in my first column. The mxml looks like this:

      <mx:DataGridColumn headerText="Correct">
      <mx:itemRenderer>
      <mx:Component>
      <mx:VBox horizontalAlign="center">
      <mx:RadioButton id="myRadioButton"
      buttonMode="true" useHandCursor="true"
      group="{outerDocument.myRadioButtonGroup}" selected="{data.correct}"/>
      </mx:VBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>

      The problem is that the radio buttons' selected properties aren't bound to the xml, that is the one that is true doesn't display as selected. If I set the datagridcolumn's editable property to false, clicking on the radio button doesn't affect the xml at all either. If I leave the editable property of the datagridcolumn as the inherited default of true (based on the parent datagrid's editable property) when I click on the radio button the default itemEditor appears (a text input box) which contains the following text:

      </answer>

      and when I leave the editor (click outside or hit enter) the xml then looks like this:

      <answers>
      <answer>
      <correct>true</correct>
      <text>Luther Higgs</text>
      </answer>
      <answer>
      <correct>false</correct>
      <text>Barney Fife</text>
      <null>&lt;answer&gt;
      &lt;correct&gt;false&lt;/correct&gt;
      &lt;text&gt;Barney Fife&lt;/text&gt;
      &lt;/answer&gt;</null>
      </answer>
      </answers>

      I have seen controls that don't have the xml path written correctly display the entire xml node rather than just the contained data, but I can think of no reason anything should Ever reference just the closing tag. To me this looks like a bug in the data bindings between the radio button and the xml object.

      Just to clear the air to avoid suggestions that will work but not meet the design requirements, what I need is a datagrid that has a radio button group (only one correct answer out of the group) in the first column and strings in the second column which need to be editable. I suppose I could write some hairy event listener code and manually hack things together, but aside from avoiding that headache, I'd love to use data bindings for what they were intended for - I just need to know why it doesn't appear to be working right. Much thanks in advance for any and all help.