Flex: How do I access data in my flex form and submit it to ColdFusion cfc?

I want to represent flex form values ​​in ColdFusion cfc.

If I have a flexible form (see below) is the data in the form of an object? Or do I need to create an object based on an id in the form and then pass that new object to the coldfusion component?

<mx:Form x="10" y="10" width="790" id="myFrom" defaultButton="{createReport}">
    <mx:FormItem label="Resume Report Type:">
    <mx:RadioButtonGroup id="showtype"/>
    <mx:HBox>
        <mx:RadioButton groupName="showtype" id="NotUpdated" value="notupdated" label="Not Updated" width="100"  />
        <mx:RadioButton groupName="showtype" id="Updated" value="updated" label="Updated" width="75"  />
        <mx:RadioButton groupName="showtype" id="All" value="all" label="All" width="75"  />
    </mx:HBox>
    </mx:FormItem>
    <mx:FormItem label="User Organzation:">
        <mx:ComboBox dataProvider="{qOrganization}" labelField="UserOrganization" />    </mx:FormItem>

    <mx:FormItem label="Between the following dates:">
        <mx:HBox>
            <mx:DateField/>
            <mx:DateField left="10"/>
        </mx:HBox>
    </mx:FormItem>
    <mx:FormItem>

        <mx:Button label="Create Report" id="createReport"/>
    </mx:FormItem>  
    </mx:Form>

      

+1


source to share


2 answers


There is no data bound to any controls on the form (other than the dataProvider for the ComboBox). If you want to retrieve data from a form with minimal changes, assign an "id" property to each control and access them programmatically from ActionScript:



var obj : MyObject = new MyObject();
obj.beginDate = beginDate.selectedDate;
obj.endDate = endDate.selectedDate;
obj.organization = Organization(comboOrg.selectedItem);
// etc

      

+1


source


No, it is not a collection or an object for all form variables (it would be too easy).

If that's what you want, you can create a custom object like Big Red Dog (brd6644). This is optional though; you don't need to create an object before submitting it. You can simply pass each field as an argument, referencing them by their ID. It really depends on preference and whether your CF service is OO dependent.

You also have the option to create a data model and send it back to CF like this:



<!-- DATA MODEL -->
<mx:Model id="formModel">
    <form>
        <beginDate>{beginDate.selectedDate}</beginDate>
        <endDate>{endDate.selectedDate}</endDate>
        <organization>
            <name></name>
            <address></address>
        </organization>
    </form>
</mx:Model>

<!-- REMOTE OBJECT/SERVER SIDE FORM HANDLER -->
<mx:RemoteObject
    id="roSubmitForm"
    source="com.mycfc"
    destination="ColdFusion"
    showBusyCursor="true">

    <mx:method name="submitForm" result="onSubmit(event)">
        <mx:arguments>
            <form>
                <beginDate>{formModel.beginDate}</beginDate>
                <endDate>{formModel.endDate}</endDate>
                <organization>
                    <name>formModel.organization.name</name>
                    <address>formModel.organization.address</address>
                </organization>
            </form>
        </mx:arguments>
    </mx:method>
</mx:RemoteObject>

      

Read more about Flex Data Models ... I'm still not completely sold out on their usefulness ... but this is another option.

+1


source







All Articles