5 Replies Latest reply on Jun 4, 2012 2:48 PM by davidflash123

    DataProvider: Is it possible

    davidflash123

      Hi All, I'm a newbie.  Question:  Is it possible to have one dataprovider call via an HttpService call and use the same data in both a datagrid and a comboBox or ListBox.  Can the data type be XML in the HttpService call.  Or do I have to use "ex4" data type to use for my comboBox????

       

      Are there any examples /scripts to look at???

       

      Thanks for taking the time.

        • 1. Re: DataProvider: Is it possible
          sumit.king7 Level 1

          Yes you can use type XML for setting the data provider for any of the three controls(combobox, datagrid, listbox).

           

          see the example I prepared:

           

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

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

                    <mx:List x="303" y="34" dataProvider="{dataXml.name}"></mx:List>

                    <mx:DataGrid x="522" y="37" dataProvider="{dataXml.name}">

           

                    </mx:DataGrid>

                    <mx:ComboBox x="864" y="38" dataProvider="{dataXml.name}"></mx:ComboBox>

           

           

                    <mx:Script>

                              <![CDATA[

           

                                        private var dataXml:XML = <root>

                                                                                                    <name>A</name>

                                                                                                    <name>B</name>

                                                                                                    <name>C</name>

                                                                                          </root>

           

                              ]]>

                    </mx:Script>

          </mx:Application>

          • 2. Re: DataProvider: Is it possible
            davidflash123 Level 1

            Sumit Jain, I tried your example, but got this error on line 16.  See my code below.  Thanks for your asistance.

             

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                  xmlns:s="library://ns.adobe.com/flex/spark"
                  xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                  creationComplete="userRequest.send()">


            <fx:Declarations>
              <s:HTTPService id="userRequest" url="http://localhost:8500/PostalTest2-debug/test1.cfm"
                    useProxy="false" method="POST">
               <mx:request xmlns="">
                <username>{username.text}</username>
                <emailaddress>{emailaddress.text}</emailaddress>
               </mx:request>        
              </s:HTTPService>
              <mx:script>
              <![CDATA[
               private var userRequest:XML = <users>
               <name>username</name>
               <name>emailaddress</name>
               </users>
               ]]>
              </mx:Script>
            </fx:Declarations>
            <mx:Form x="22" y="10" width="300">
              <mx:FormItem>
               <s:Label text="Username" />    
               <s:TextInput id="username"/>
              </mx:FormItem>
              <mx:FormItem>
               <s:Label text="Email Address" />    
               <s:TextInput id="emailaddress"/>
              </mx:FormItem>
              <s:Button label="Submit" click="userRequest.send()"/>
            </mx:Form>

            <mx:DataGrid id="dgUserRequest" x="573" y="18" height="556"
                 dataProvider="{userRequest.lastResult.users.user}">
              <mx:columns>
               <mx:DataGridColumn headerText="User ID" dataField="username"/>
               <mx:DataGridColumn headerText="User Name" dataField="emailaddress"/>
              </mx:columns>
            </mx:DataGrid>
            <s:TextInput x="22" y="300" id="selectedemailaddress" text="{dgUserRequest.selectedItem.emailaddress}"/>
            <mx:ComboBox x="864" y="38" dataProvider="{userRequest.username}"></mx:ComboBox>
            </s:Application>

            • 3. Re: DataProvider: Is it possible
              davidflash123 Level 1

              Problem solved,  I was able to locate some solutions to solve my combobox problem.  I am now able to load data into the combobox.   Now I just need to figrue out how to update the backend database when I select a data from either the datagrid or combobox.

               

              See below

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                    creationComplete="userRequest.send()">


              <fx:Declarations>
                <s:HTTPService id="userRequest" url="http://localhost:8500/PostalTest2-debug/test1.cfm"
                      useProxy="false" method="POST">
                 <mx:request xmlns="">
                  <username>{username.text}</username>
                  <emailaddress>{emailaddress.text}</emailaddress>
                 </mx:request>        
                </s:HTTPService>
              </fx:Declarations>
              <mx:Form x="22" y="10" width="300">
                <mx:FormItem>
                 <s:Label text="Username" />    
                 <s:TextInput id="username"/>
                </mx:FormItem>
                <mx:FormItem>
                 <s:Label text="Email Address" />    
                 <s:TextInput id="emailaddress"/>
                </mx:FormItem>
                <s:Button label="Submit" click="userRequest.send()"/>
              </mx:Form>
              <s:ComboBox x="864" y="38" dataProvider="{userRequest.lastResult.users.user}"
              labelField= "username">
              </s:ComboBox>

              <mx:DataGrid id="dgUserRequest" x="573" y="18" height="556"
                   dataProvider="{userRequest.lastResult.users.user}">
                <mx:columns>
                 <mx:DataGridColumn headerText="User ID" dataField="username"/>
                 <mx:DataGridColumn headerText="User Name" dataField="emailaddress"/>
                </mx:columns>
              </mx:DataGrid>
              <s:TextInput x="22" y="300" id="selectedemailaddress" text="{dgUserRequest.selectedItem.emailaddress}"/>

              </s:Application>

              • 4. Re: DataProvider: Is it possible
                sumit.king7 Level 1

                I think instead of using HTTP service, use Remoting so that u can call a ColdFusion Component function directly.

                 

                Now, Apply a change event on combobox. And in the change handler function of combobox, call the coldfusion component function which in turn updates ur database.

                 

                I suggest, go for remoting.

                • 5. Re: DataProvider: Is it possible
                  davidflash123 Level 1

                  frustrated newbie.  I using this code by is getting this error:

                   

                  "[MessagingError message='Destination 'ColdFusion' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']"

                   

                  My code:

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

                  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                        xmlns:s="library://ns.adobe.com/flex/spark"

                        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

                  <fx:Declarations>

                    <mx:RemoteObject

                     id="userRequest"

                     destination="ColdFusion"

                     source="//xxxxx.xxx.com/webdata/IS/ACE3-Data/cfc/PrinterSitesTable.cfm">

                     <mx:method name="GetAllLocations" result="returnHandler(event)"

                          fault="mx.controls.Alert.show(event.fault.faultString)"/>

                    

                  <!--  <mx:method name="insertRecord" result="insertHandler()"

                          fault="mx.controls.Alert.show(event.fault.faultString)"/>

                    -->

                    

                    </mx:RemoteObject>

                  </fx:Declarations>

                   

                  <fx:Script>

                    <![CDATA[

                     import mx.rpc.events.ResultEvent;

                    

                     private function returnHandler(e:ResultEvent):void 

                     {

                      dgUserRequest.dataProvider = e.result;

                     }

                  // <!-- private function insertHandler():void 

                  //  {

                  //   userRequest.GetAllLocations();

                  //  }

                  //  private function clickHandler():void 

                  //  {

                  //   userRequest.insertRecord(username.text, emailaddress.text);

                  //  } 

                  // -->

                    ]]>

                  </fx:Script>

                   

                  <mx:Form x="22" y="10" width="300">

                    <mx:FormItem>

                     <s:Label text="Username" />    

                     <s:TextInput id="username"/>

                    </mx:FormItem>

                    <mx:FormItem>

                     <s:Label text="Email Add" />    

                     <s:TextInput id="emailaddress"/>

                    </mx:FormItem>

                    <s:Button label="Submit" click="userRequest.GetAllLocations()"/>

                  </mx:Form>

                   

                  <mx:DataGrid id="dgUserRequest" x="22" y="200" width="754" height="364">

                    <mx:columns>

                     <mx:DataGridColumn headerText="User ID" dataField="FacilityDatabaseID"/>

                     <mx:DataGridColumn headerText="User Name" dataField="FACILITY_NAME"/>

                    </mx:columns>

                  </mx:DataGrid>

                  </s:Application>

                   

                   

                  My problem is that I do not know what to put in :

                   

                  destination="ColdFusion"  

                     source="//xxxxx.xxx.com/webdata/IS/ACE3-Data/cfc/PrinterSitesTable.cfc">

                   

                  My development is on my local PC, but I want to reference my coldfusion cfc on my actual production server.  This server is my share server, I do not know where our actual Coldfusion server is located.  All I know is that when I run my Coldfusion apps, the worked when using and calling cfc's.

                   

                  So my think is that once I officially launch the app on our production server, the destination source will already be in place.  I just do not know how to reference the source.    All I can tell you is that the cfc's that I use when running Coldfusion programs are located in my "webdata/IS/ACE-Data/cfc folder. 

                   

                  Now I trying to use Flex to reference my Coldfusion cfc's and I do not know what to used for the source.

                   

                  Can I use for the source =  "http://servername.com/webdata/IS/ACE3-Data/cfc/PrinterSitesTable.cfc.

                  or source = //servername/webdata/IS/ACE3-Data/cfc/PrinterSitesTable.cfc.

                   

                  I read about services-config.xml but it seems that file must go under the actual Coldfusion server (which I do not have access to nor know where the server located.

                   

                  Can you or anyone assist.

                   

                  Thanks.