3 Replies Latest reply on Jun 17, 2007 3:14 PM by BLXWebMaster

    Problem using CFC as datasource

    peterdoyle
      Hi Hoping someone can help me with a pretty basic problem.

      I am trying to use a cfc as the datasource for a combobox and also for a tilelist but I have to say I think I am missing something obvious.

      The problem is that when using the code below for my combobox it is only showing one result not the whole list that I am expecting. I expect this is something to do with the way I am setting up the cfc but any help would be appreciated.

      Cheers
      Peter

      First the cfc:

      cffunction name="getClans" access="remote" returntype="struct">
      <cfset var clans = "" />
      <cfset var clansStruct = StructNew() />
      <cfquery datasource="readyup" name="clans">
      SELECT * FROM TabClans
      </cfquery>
      <cfloop query="clans">
      <cfset temp = structnew()>
      <cfset temp.clanid = clanid />
      <cfset temp.ClanName = ClanName />
      <cfset temp.ClanHomePage = ClanHomePage />

      <cfset structappend(clansStruct, temp)>

      </cfloop>

      <cfreturn clansStruct>
      </cffunction>

      The code for the combo is as follows:


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="myService.getClans()" >
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.controls.Button;
      import mx.controls.Alert;
      public function handleStructResult(event:ResultEvent):void{
      oResult=event.result as Object;
      }
      [Bindable]
      public var oResult:Object;

      ]]>
      </mx:Script>
      <mx:RemoteObject id="myService" destination="ColdFusion" source="readyup" showBusyCursor="true">
      <mx:method name="getClans" result="handleStructResult(event)" fault="Alert.show(event.fault.message)"/>
      </mx:RemoteObject>
      <mx:ComboBox x="10" y="100" dataProvider="{oResult}" labelField="oResult.CLANID"></mx:ComboBox>
        • 1. Re: Problem using CFC as datasource
          BLXWebMaster Level 1
          This is how I would code what you are trying to do.

          Remember: The FieldNames returned from your query are case sensitive when you reference them in your labelfield of your combobox.

          <cffunction name="getClans" output="false" access="remote" returntype="query">
          <cfset var qRead="">
          <cfquery name="qRead" datasource="readyup">
          SELECT * FROM TabClans
          </cfquery>
          <cfreturn qRead>
          </cffunction>

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          layout="absolute"
          creationComplete="creationComplete();">

          <mx:Script>
          <![CDATA[
          import mx.collections.*;
          import mx.controls.*;
          import mx.rpc.events.*;
          import mx.events.*;

          private function creationComplete():void{
          myService.getClans.send();
          }

          [Bindable]
          private var arClans:ArrayCollection = null;
          private function getClansReceived(event:ResultEvent):void {
          arClans = new ArrayCollection();
          arClans = event.result as ArrayCollection;
          }
          ]]>
          </mx:Script>

          <mx:RemoteObject id="myService" destination="ColdFusion" source="readyup" showBusyCursor="true">
          <mx:method name="getClans" result="getClansReceived(event)" fault="Alert.show(event.fault.message)"/>
          </mx:RemoteObject>

          <mx:ComboBox x="10" y="100" dataProvider="{arClans}" labelField="CLANID"></mx:ComboBox>

          </mx:Application>
          • 2. Re: Problem using CFC as datasource
            peterdoyle Level 1
            Thanks and this does work. This is the same type of thing I have done with some other queries returning arrays which works as well.

            The reason I was trying to return a structure was because I though that i would need this if I wanted to use the same service to create a tilelist using the other fields from this query as well? Or can I use a query as the datasource for this?

            Thanks
            Peter
            • 3. Re: Problem using CFC as datasource
              BLXWebMaster Level 1
              Returning a query is fine and can be used for anything. As long as the field is in the query, it will be available in your arcollection to do whatever you like with it.