PDA

View Full Version : returning results from a webservice


adrock3000
01-18-2007, 04:47 PM
first and foremost i am web developer new to flex/actionscript/coldfusion. i have a java background but this language is new to me. i keep getting syntax errors and i am not sure what i need to do in this situation. i am trying to populate a datagrid with the results from a search to a mySQL db using cf and im pretty sure i have it for the most part im just not sure how to get the results from an "event" from what i was told the results where coming back in, to a object/array that i can bind as a dataprovider. right now i am getting an implicit coercion error from the results property of the webservice. this code is still in progress...sorry
any help anyone can give me would be greatly appreciated...tia

ps. i know theres a whole bunch of extra imports in there


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


<mx:Script>
<![CDATA[
import mx.events.ResizeEvent;
import mx.utils.ObjectProxy;
import mx.rpc.events.AbstractEvent;

import mx.controls.Alert;

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import flash.utils.*;
import mx.rpc.events.*;

import mx.managers.PopUpManager;
import mx.core.IFlexDisplayObject;
import mx.controls.*;
import asFiles.*;

[Bindable]
public var searchObj:SearchConstructor;
private var searchWebService:SearchWebService;
private var searchResults:Array;

public function createObj()
{
searchWebService=new SearchWebService();
addChild(searchWebService);
searchObj = new SearchConstructor(searchCombo.text, searchInput.text)
searchWebService.myService.SearchWeb(searchObj.sea rchString, searchObj.searchField);

}

public function openWindow(event:ResultEvent)
{
searchResults = event;

}


]]>
</mx:Script>

<mx:WebService
id="jobBoardService"
wsdl="http://www.blah.com/JobBoard.cfc?wsdl"
showBusyCursor="true"
concurrency="multiple">

<mx:operation name="SearchWeb" result="openWindow(event)" resultFormat="object">
<mx:request>
</mx:request>
</mx:operation>

</mx:WebService>




<mx:Panel x="10" y="10" width="315" height="165" layout="absolute" title="Search">
<mx:Form x="10" y="10">
<mx:FormItem label="Search For:">
<mx:TextInput id="searchInput"/>
</mx:FormItem>
<mx:FormItem label="in:">
<mx:ComboBox id="searchCombo" dataProvider="[HONAME,ADDRESS,CITY,STATE,PHONE,ACCOUNT]">
</mx:ComboBox>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Search" id="srchButton" click="createObj()"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
<mx:DataGrid x="176.5" y="239" dataProvider="searchResults">

</mx:DataGrid>

</mx:Application>

meddlingwithfir
01-19-2007, 04:48 PM
I haven't looked through your code, but we had a good discussion on how to get data out of ColdFusion here:

http://www.actionscript.org/forums/showthread.php3?t=122272

Edit: Ahh, you're using Web Services, which might be a little different than what we talked about in that above post. I've been using Remote Objects.

CFC:

<cffunction name="getAllUsers" returntype="User[]">
<cfargument name="userID" required="false" />
<cfargument name="username" required="false" />
<cfargument name="password" required="false" />

<cfquery name="records" datasource="#Request.DSName#">
SELECT *
FROM Users
WHERE 0=0
<cfif isDefined('arguments.userID') AND isNumeric(arguments.userID)>
AND Users.userID = <cfqueryparam value="#arguments.userID#" cfsqltype="cf_sql_integer" />
</cfif>
<cfif isDefined('arguments.username')>
AND Users.username = <cfqueryparam value="#arguments.username#" cfsqltype="cf_sql_varchar" />
</cfif>
<cfif isDefined('arguments.password')>
AND Users.password = <cfqueryparam value="#arguments.password#" cfsqltype="cf_sql_varchar" />
</cfif>;
</cfquery>

<cfset returnArray = ArrayNew(1)>

<cfloop query="records">
<cfscript>
thisUser = CreateObject("Component","User");
thisUser.setUserID(records.userID);
thisUser.setUsername(records.username);
thisUser.setPassword(records.password);
thisUser.setFirstName(records.firstName);
thisUser.setLastName(records.lastName);
thisUser.setisActive(records.isActive);
thisUser.setEmail(records.email);
thisUser.setDateAdded(records.dateAdded);
ArrayAppend(returnArray, thisUser);
</cfscript>
</cfloop>

<cfreturn returnArray />
</cffunction>



MXML:


[Bindable] private var COMPONENTPATH:String = "other.VI-RD.FlexCIS.Components";

<mx:RemoteObject
id="userController"
destination="ColdFusion"
showBusyCursor="true"
source="{COMPONENTPATH}.UserController"
fault="Alert.show(event.fault.faultString, 'Error');"
>
<mx:method name="getAllUsers" result="getAllUsersResult(event)" />
</mx:RemoteObject>


private function getAllUsersResult( event:ResultEvent )
{
var myUsers:Array = event.result as Array;
}


From there you ought to be able to loop over that array and call any of the field names you passed back from ColdFusion. Store those results in a [Bindable] array, and you ought to be able to have that Array as your dataProvider.