<cffunction returnType="DataVO[]"> this works the best, returns a true array of objects to Flex. Define DataVO in a separate CFC.
On 8/12/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Thanks, Jeff. That helps... > > I'm still stuck on how to handle the return recordset from the cfc. If case > sensitivity doesn't matter, how do you recommend dynamically getting all the > data into the structure? > > <cfoutput query="qGetUpdateAuthorization"> > <cfset stItem = StructNew()/> > <cfset stItem["label"] = #queryname.columnList#/> > <cfset stItem["data"] = data/> > <cfset ArrayAppend(arrResult,stItem)/> > > </cfoutput> > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] > Behalf Of Battershall, Jeff > Sent: Friday, August 12, 2005 6:38 AM > To: [email protected] > Subject: RE: [flexcoders] Calling ArrayStructures in CFCs from Flex > > > Darius, > > What you want is an array of structures (what Flex wants), not a structure > of arrays (what a CF Query is). By using queryname.columnList, you get the > keys you want to dynamically populate each structure, but unfortunately, > case sensitivity of column names isn't preserved - so you may end up hard > coding each structure key if case sensitivity of your struct keys matters to > your application. Also, your cfset var will have to be placed at the top of > the function body, just after your CFARGUMENT tags. > > Jeff > > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of [EMAIL PROTECTED] > Sent: Thursday, August 11, 2005 5:57 PM > To: [email protected] > Subject: RE: [flexcoders] Calling ArrayStructures in CFCs from Flex > > > Jeff, > > Great example! It almost works for me except the cfc I call from Flex is a > facade to my cfc query. The cfc query returns a variable that needs to be > converted to an array or whatever before being put into a structure. Do you > have any ideas how to do this? Many thanks, Darius > > <cfcomponent> > > <!--- Data coming in from Flex ---> > <cffunction name="invUpdateAuthorization" access="remote" > returnType="Array"> > <cfargument name="Input" required="true" type="Array"> > <cfset AuthorizedUserId = input[1] > > <cfset CCode = input[2] > > <cfset CFlag = input[3] > > <cfset COAvailableFlag = input[4] > > <cfset Dsn = input[5] > > <cfset ComponentPath = > "Model.mUtilities.mUpdate.qry_UpdateAuthorization"> > > <!--- This is the call to the query that returns the recordset > qGetUpdateAuthorization ---> > <cfinvoke component="#ComponentPath#" method="GetUpdateAuthorization" > returnvariable="qGetUpdateAuthorization"> > <cfinvokeargument name="AuthorizedUserId" value="#AuthorizedUserId#"> > <cfinvokeargument name="CountyCode" value="#CountyCode#"> > <cfinvokeargument name="CaseFlag" value="#CaseFlag#"> > <cfinvokeargument name="CourtOrderAvailableFlag" > value="#CourtOrderAvailableFlag#"> > <cfinvokeargument name="Dsn" value="#Dsn#"> > </cfinvoke> > > <!--- How do I get this component recordset into your Structure of arrays? > ---> > > <cfset var arrResult = ArrayNew(1)/> > <cfset var stItem = StructNew()/> > > > <cfoutput query="qGetUpdateAuthorization"> > <cfset stItem = StructNew()/> > <cfset stItem["label"] = label/> > <cfset stItem["data"] = data/> > <cfset ArrayAppend(arrResult,stItem)/> > > </cfoutput> > > <cfreturn arrResult/> > > > > </cffunction> > > </cfcomponent> > > > > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of Battershall, Jeff > Sent: Thursday, August 11, 2005 8:38 AM > To: [email protected] > Subject: RE: [flexcoders] Calling ArrayStructures in CFCs from Flex > > I'm jonny-come-lately to this thread, but I send and return arrays and > structures to/from CFCs all the time. I've abandoned passing back > CFQueries as such but convert them to an array of structures first as > that is what Flex UIComponents seem to like. > > Example code: > > <cffunction name="getIndustryCategories" returntype="array" > access="public"> > > <cfset var arrResult = ArrayNew(1)/> > <cfset var stItem = StructNew()/> > > <cfstoredproc > procedure="sp_GetIndustryCategories" > datasource="#getDataSource()#"> > <cfprocresult name="qryCats"/> > </cfstoredproc> > > <cfoutput query="qryCats"> > <cfset stItem = StructNew()/> > <cfset stItem["label"] = label/> > <cfset stItem["data"] = data/> > <cfset arrayAppend(arrResult,stItem)/> > > </cfoutput> > > <cfreturn arrResult/> > > </cffunction> > > If you were dealing with a dynamic list of columns the code could be > altered as such: > > <cfoutput query="qryCats"> > > <cfset stItem = StructNew()/> > > <cfloop list="#qryCats.columnList#" index="i"> > <cfset stItem[i] = qryCats[i][currentrow]/> > </cfloop> > > <cfset arrayAppend(arrResult,stItem)/> > > > </cfoutput> > > Produced in this fashion, Flex WILL accept this result as an array of > structures. I'm mystified at the problem you're experiencing. > > Jeff > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of Malcolm > Sent: Wednesday, August 10, 2005 7:48 PM > To: [email protected] > Subject: RE: [flexcoders] Calling ArrayStructures in CFCs from Flex > > > Hi Darius, > > I too went through the same pain (days & days of trying see what data > types I could successfully return from a CFC). > > I'm still learning but in my somewhat limited experience I could find no > way to return an array datatype, it just wouldn't do it no matter what I > tried, same goes for structures. I have successfully returned the > following > datatypes: > > :String > :Query > :Boolean > > :Numeric (yet to try) > :Date (yet to try) > > It's interesting to note that Flex (somehow) in the background actually > converts a ColdFusion query to an array. (Search the group on how these > can be accessed) > > At the moment I am mostly using queries to get data back. This has the > unfortunate side effect of losing typing (everything in the query is a > string), thus you may need cast some results etc to their correct type > in Flex. > > Malcolm > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of coldfs > Sent: Friday, 5 August 2005 7:29 AM > To: [email protected] > Subject: [flexcoders] Calling ArrayStructures in CFCs from Flex > > Hi, > > Using Tom Link's blog (http://tomlink.net/blog/index.cfm? > mode=entry&entry=B662BEF9-7E97-A3B0-E3FB286E23BDAA50) and > other > sources, I've been trying for days to translate queries to arrays of > structures (and vice versa). Whatever I do, the cfc doesn't except > my values from Flex as arrays. I know it's a chunk of code to > review, but you'd help a sane man going slowly mad...:-) > > Many thanks, > Darius > > ----------- > index.mxml: > ----------- > <?xml version="1.0" encoding="utf-8"?> > <mx:Application > xmlns:mx="http://www.macromedia.com/2003/mxml"> > > <mx:Script> > <![CDATA[ > > var RecordSetModel; > > private function doResult(event:Object):Void{ > var method: String = > event.call.methodName; > if (method > == "GetUpdateAuthorization"){ > RecordSetModel = event.result; > } > } > > private function doClick():Void{ > var UserId = "rgatta"; > > var CountyCode = 37; > var CaseFlag = "No"; > var CourtOrderAvailableFlag = "No"; > var Dsn = "TssDev"; > ro.GetUpdateAuthorization > (UserId,CountyCode,CaseFlag,CourtOrderAvailableFlag,Dsn); > } > ]]> > </mx:Script> > > > <mx:RemoteObject id="ro" > endpoint="http://gx270dev.net/flashservices/gateway" > source="Model.mUtilities.mUpdate.qry_UpdateAuthorization" > fault="mx.controls.Alert.show(event.fault.faultstring)" > showBusyCursor="true"> > <mx:method name="GetUpdateAuthorization" > result="doResult(event.result)"/> > </mx:RemoteObject> > > <mx:Panel width="100%" title="Forms" height="22%"> > <mx:DataGrid id="UpdatesDG" width="166" height="156" > wordWrap="true" dataProvider="{RecordSetModel}"> > <mx:columns> > <mx:Array> > <mx:DataGridColumn > width="200" headerText="Update Form" columnName="Function"/> > <mx:DataGridColumn > width="320" headerText="Description" columnName="Description"/> > </mx:Array> > </mx:columns> > </mx:DataGrid> > <mx:Button label="Get Records" click="doClick()"/> > </mx:Panel> > > </mx:Application> > > -------------------------- > fx_UpdateAuthorization.cfc > -------------------------- > <cfcomponent extends="Base"> > > <cfset obj = createObject > ("component","qry_UpdateAuthorization")> > > <!--- <cffunction name="getEmployees" access="remote" > returntype="array"> > <cfreturn queryToArrayOfStructures(emp.getEmployees()) > > > </cffunction> ---> > > <cffunction name="GetUpdateAuthorization" access="remote" > returntype="array"> > <cfargument name="AuthorizedUserIdObject" > type="array" required="yes"> > <cfargument name="CountyCodeObject" type="array" > required="yes"> > <cfargument name="CaseFlagObject" type="array" > required="yes"> > <cfargument > name="CourtOrderAvailableFlagObject" > type="array" required="yes"> > <cfargument name="DsnObject" type="array" > required="yes"> > <cfreturn queryToArrayOfStructures > (obj.GetUpdateAuthorization > (AuthorizedUserIdObject,CountyCodeObject,CaseFlagObject,CourtOrderAvai > lableFlagObject,DsnObject))> > </cffunction> > > </cfcomponent> > > ----------------------------- > qry_UpdateAuthorization.cfc > ----------------------------- > <cfcomponent extends="Base"> > > <cffunction name="GetUpdateAuthorization" access="remote" > returntype="query"> > > <cfargument name="AuthorizedUserId" type="array" > required="yes"> > <cfargument name="CountyCode" type="array" > required="yes"> > <cfargument name="CaseFlag" type="array" > required="yes"> > <cfargument name="CourtOrderAvailableFlag" > type="array" required="yes"> > <cfargument name="Dsn" type="array" required="yes"> > > <CFSTOREDPROC PROCEDURE="spUpdateAuthorization" > DATASOURCE="#Arguments.Dsn#"> > <CFPROCPARAM DBVARNAME="AuthorizedUserId" > TYPE="IN" VALUE="#Arguments.AuthorizedUserId#" > CFSQLTYPE="CF_SQL_CHAR"> > <CFPROCPARAM DBVARNAME="CountyCode" TYPE="IN" > VALUE="#Arguments.CountyCode#" CFSQLTYPE="CF_SQL_CHAR"> > <CFPROCPARAM DBVARNAME="CaseFlag" TYPE="IN" > VALUE="#Arguments.CaseFlag#" CFSQLTYPE="CF_SQL_CHAR"> > <CFPROCPARAM > DBVARNAME="CourtOrderAvailableFlag" TYPE="IN" > VALUE="#Arguments.CourtOrderAvailableFlag#" > CFSQLTYPE="CF_SQL_CHAR"> > <CFPROCRESULT NAME="qGetUpdateAuthorization"> > </CFSTOREDPROC> > > <cfreturn qGetUpdateAuthorization> > > </cffunction> > > </cfcomponent> > > ------------- > Base.cfc > ------------- > <cfcomponent> > > <cffunction name="dumpToFile" access="package" hint="A quick > and easy debugging utility when testing with Flash."> > <cfargument name="dumpObject" type="any" > required="yes"> > <cfargument name="path" type="string" required="yes"> > <cfset var varToOutput=""> > <cfsavecontent variable="varToOutput"> > <cfdump var="#arguments.dumpObject#"> > </cfsavecontent> > <cffile action="write" file="#arguments.path#" > addnewline="yes" output="#varToOutput#"> > </cffunction> > > <cfscript> > /** > * Converts a query object into an array of structures. > * > * @param query The query to be transformed > * @return This function returns a structure. > * @author Nathan Dintenfass ([EMAIL PROTECTED]) > * @version 1, September 27, 2001 > */ > function QueryToArrayOfStructures(theQuery){ > var theArray = arraynew(1); > var cols = ListtoArray(theQuery.columnlist); > var row = 1; > var thisRow = ""; > var col = 1; > for(row = 1; row LTE theQuery.recordcount; row = row > + 1){ > thisRow = structnew(); > for(col = 1; col LTE arraylen(cols); col = > col + 1){ > thisRow[cols[col]] = theQuery[cols > [col]][row]; > } > arrayAppend(theArray,duplicate(thisRow)); > } > return(theArray); > } > > /** > * Converts an array of structures to a CF Query Object. > * 6-19-02: Minor revision by Rob Brooks-Bilson > ([EMAIL PROTECTED]) > * > * Update to handle empty array passed in. Mod by Nathan > Dintenfass. Also no longer using list func. > * > * @param Array The array of structures to be > converted to a query object. Assumes each array element contains > structure with same (Required) > * @return Returns a query object. > * @author David Crawford ([EMAIL PROTECTED]) > * @version 2, March 19, 2003 > */ > function arrayOfStructuresToQuery(theArray){ > var colNames = ""; > var theQuery = queryNew(""); > var i=0; > var j=0; > //if there's nothing in the array, return the empty > query > if(NOT arrayLen(theArray)) > return theQuery; > //get the column names into an array = > colNames = structKeyArray(theArray[1]); > //build the query based on the colNames > theQuery = queryNew(arrayToList(colNames)); > //add the right number of rows to the query > queryAddRow(theQuery, arrayLen(theArray)); > //for each element in the array, loop through the > columns, populating the query > for(i=1; i LTE arrayLen(theArray); i=i+1){ > for(j=1; j LTE arrayLen(colNames); j=j+1){ > querySetCell(theQuery, colNames[j], > theArray[i][colNames[j]], i); > } > } > return theQuery; > } > </cfscript> > > </cfcomponent> > > > > > > > > > -- > Flexcoders Mailing List > FAQ: > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > > > > > > > > -- > Flexcoders Mailing List > FAQ: > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > > > > > > > > > -- > Flexcoders Mailing List > FAQ: > http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > > > > > SPONSORED LINKS > Computer software testing Macromedia flex Development > Software developer > > ________________________________ > YAHOO! GROUPS LINKS > > > Visit your group "flexcoders" on the web. > > To unsubscribe from this group, send an email to: > [EMAIL PROTECTED] > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. > > ________________________________ > -- Jordan Snyder Applications Developer ImageAction, USA http://www.imageaction.com ------------------------ Yahoo! Groups Sponsor --------------------~--> <font face=arial size=-1><a href="http://us.ard.yahoo.com/SIG=12hi30rsm/M=362329.6886308.7839368.1510227/D=groups/S=1705007207:TM/Y=YAHOO/EXP=1123881021/A=2894321/R=0/SIG=11dvsfulr/*http://youthnoise.com/page.php?page_id=1992 ">Fair play? Video games influencing politics. Click and talk back!</a>.</font> --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

