passing selectedItem data from a component

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default passing selectedItem data from a component

    I need help as I could not figure out my mistake ? I have main application page
    and two components. The main page calls for the first component to display
    data based on a selectedItem from a dataGrid of the main page and this works
    very well. However, when I use the datagrid in the first component to pass the
    property 'selectedDx' to the second component I can not get the dataObject to
    be passed to the main page or second component. The property I am trying to
    pass is 'selected Dx' in the below example Thank you from a newbie. HT

    //main mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" width="815">
    <mx:HTTPService id="dxListSrv" url="jspDiagnoses.jsp">
    <mx:request>
    <ptId>{dgPatients.selectedItem.patientID}</ptId>
    </mx:request>
    </mx:HTTPService>

    <mx:Script>
    <![CDATA[
    var selectedPt;
    var selectedDx:Object;

    function selectPtData(event){
    selectedPt=event.target.selectedItem;
    dxListSrv.send();

    }

    ]]>
    </mx:Script>

    <mx:Model id="patientModel" source="xmlPatients.xml"></mx:Model>

    <mx:HBox>
    <mx:DataGrid id="dgPatients" dataProvider="{patientModel.patient}"
    change="selectPtData(event);" >
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="patientID"></mx:DataGridColumn>
    <mx:DataGridColumn columnName="MRN"></mx:DataGridColumn>
    <mx:DataGridColumn columnName="firstName"></mx:DataGridColumn>
    <mx:DataGridColumn columnName="lastName"></mx:DataGridColumn>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    <local:PatientIdDetail xmlns:local="*" id="patientIdDetail" ptIdObject =
    "{selectedPt}"/>
    <mx:VBox>
    <local:DiagnosesList id="dxList" xmlns:local="*" dxListObject =
    "{dxListSrv.result.diagnoses.diagnosis}"
    change="selectedDx=event.target.selectedItem" />
    <mx:DataGrid dataProvider="{mx.utils.ArrayUtil.toArray(selected Dx)}">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="description"></mx:DataGridColumn>
    <mx:DataGridColumn columnName="diagnosisID"></mx:DataGridColumn>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    <local:RxList id="rxList" xmlns:local="*" rxListObject="{selectedDx}" />
    </mx:VBox>
    </mx:HBox>

    <mx:Text text="{dgPatients.selectedItem.patientID}"/>

    </mx:Application>

    ----------------------------- first component
    ------------------------------------------ DiagnosesList.mxml
    ------------------------
    <?xml version="1.0" encoding="utf-8"?>

    <mx:Panel xmlns:mx="http://www.macromedia.com/2003/mxml" title="Diagnoses"
    marginBottom="8" marginLeft="8" marginRight="4" marginTop="4">

    <mx:Metadata>
    [Event("change")]
    </mx:Metadata>

    <mx:Script>
    var dxListObject:Object;
    var selectedDx;

    function selDx(event) {
    selectedDx=event.target.selectedItem;
    selectedDx.dispatchEvent({type:"change"});
    }
    </mx:Script>

    <mx:DataGrid id="dxCmpList"
    dataProvider="{mx.utils.ArrayUtil.toArray(dxListOb ject)}"
    change="selDx(event);" >
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="description" />
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    <mx:DataGrid dataProvider="{mx.utils.ArrayUtil.toArray(selected Dx)}">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="description" />
    <mx:DataGridColumn columnName="diagnosisID" />
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>


    </mx:Panel>

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

    <mx:Panel xmlns:mx="http://www.macromedia.com/2003/mxml" title="Treatment"
    marginBottom="8" marginLeft="8" marginRight="4" marginTop="4">

    <mx:Script>
    var rxListObject:Object;

    </mx:Script>

    <mx:Model id="testList">
    <desc>{rxListObject.description}</desc>
    <ptId>{rxListObject.patientID}</ptId>
    </mx:Model>

    <mx:Text text="{testList.desc}" />
    <mx:DataGrid id="rxList" dataProvider="{mx.utils.ArrayUtil.toArray(testList )}">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="desc" />
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>


    </mx:Panel>

    fastlife Guest

  2. Similar Questions and Discussions

    1. Passing CFGRID data to CFC
      I'm trying to pass data in a cfgrid to an cfc using flash remoting. I'm passing it as myGrid.dataProvider, on the cfc side I have a CFARGUMENT of...
    2. passing an array to a web service using WS component
      I am trying to send a bunch of form values to a webservice. The service accepts 7 parameters, 5 string values and 2 arrays. I am using the web...
    3. Passing parameters to a component
      I'm trying to pass the dimensions of the main window to a component for positioning of a popup that it generates, but I keep getting the following...
    4. passing data through a database
      Hi: I made one page that passes data through a form to another page. The destination (confirmation) page checks if the user filled the form or not...
    5. viewstate restores data but selectedItem is restored late
      I have a Web Custom Control that has a checkBoxList control added to its control collection. This checkbox list control is initially populated...
  3. #2

    Default Re: passing selectedItem data from a component

    I think maybe your change event target is the panel, which doesn't have a
    selectedItem property.

    Try this:
    change="selectedDx=dxList.dxCmpList.selectedItem"

    Or, in your datagrid in the component, build an event object with the
    selectedItem in it and manually dispatch an event.

    Tracy

    ntsiii Guest

  4. #3

    Default Re: passing selectedItem data from a component

    Thank you Tracy.
    It worked right away.

    Any useful hints where I can get a little more 'learining' done on these concepts.

    Thank you again
    HT
    fastlife Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139