I apologize in advance for the length of this post!
<!--- CFC method --->
<cffunction
name="getAllBooks"
displayname="getAllBooks"
hint="I get books for display in Flex"
access="remote"
output="false"
returntype="query">
<cfquery name="qryAllBooks" datasource="books">
select * from books order by author asc
</cfquery>
<cfreturn qryAllBooks />
</cffunction>
<!-- MXML -->
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="components.*"
layout="absolute"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.Fault;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent ;
import mx.rpc.soap.mxml.WebService;
import mx.events.ValidationResultEvent;
private var vResult:ValidationResultEvent;
public function initApp():void {
}
public function handleFormResult(event:ResultEvent):void {
Alert.show("Your Book Has Been Submitted!");
}
public function handleRemotingResult(event:ResultEvent):void {
Alert.show("Remoting Result Received!");
qryDG_dg.dataProvider = event.result;
}
public function handleWebServiceResult(event:ResultEvent):void {
Alert.show("Webservice Result Received!");
wsdlDG01_dg.dataProvider = event.result;
}
public function errorHandler(event:FaultEvent):void {
Alert.show(event.fault.message);
}
public function submitBook():void {
var validFlag:Boolean = true;
var authorResult:ValidationResultEvent = authorV.validate();
var titleResult:ValidationResultEvent = titleV.validate();
var genreResult:ValidationResultEvent = genreV.validate();
var linkResult:ValidationResultEvent = linkV.validate();
if (authorResult.type == ValidationResultEvent.INVALID) {
validFlag = false;
Alert.show("Author Name must be four or more characters and no less than 1 character.");
}
if (titleResult.type == ValidationResultEvent.INVALID ) {
validFlag = false;
Alert.show("Title is required.");
}
if (genreResult.type == ValidationResultEvent.INVALID ) {
validFlag = false;
Alert.show("Genre is required and cannot be less than three characters.");
}
if (linkResult.type == ValidationResultEvent.INVALID) {
validFlag = false;
Alert.show("Link is required and cannot be less than three characters.");
}
if (validFlag)
insertBookService.addBook.send();
}
]]>
</mx:Script>
<mx:RemoteObject
id="qryService"
destination="ColdFusion"
source="remotingExample"
result="handleRemotingResult(event)"
showBusyCursor="true"
fault="errorHandler(event)"/>
<mx:WebService
id="insertBookService"
wsdl="http://localhost:8500/remotingExample.cfc?wsdl"
result="handleFormResult(event)"
showBusyCursor="true"
fault="errorHandler(event)">
<mx:operation name="addBook">
<mx:request>
<bookAuthor>{ bookAuthor.text}</bookAuthor>
<bookTitle>{bookTitle.text}</bookTitle>
<bookGenre>{bookGenre.text}</bookGenre>
<bookLink>{ bookLink.text}</bookLink>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:WebService
id="wsdlQryService"
useProxy="false"
wsdl="http://localhost:8500/remotingExample.cfc?wsdl">
<mx:operation
name="getAllBooks"
result="handleWebServiceResult(event)"
fault="errorHandler(event)"/>
</mx:WebService>
<mx:StringValidator id="authorV" source="{bookAuthor}" property="text" minLength="1" maxLength="55" required="true"/>
<mx:StringValidator id="titleV" source="{bookTitle}" property="text" required="true"/>
<mx:StringValidator id="genreV" source="{bookGenre}" property="text" required="true" minLength="3"/>
<mx:StringValidator id="linkV" source="{bookLink}" property="text" required="true" minLength="3"/>
<mx:VBox height="100%" left="10" top="10" right="10" bottom="10" id="main_vb" horizontalAlign="center" verticalAlign="top" verticalGap="10">
<mx:Panel width="50%" height="100%" layout="absolute" id="panel_for_dg" title="">
<mx:VBox width="100%" horizontalAlign="center">
<mx:DataGrid x="0" y="0" id="qryDG_dg" width="100%" height="120">
<mx:columns>
<mx:DataGridColumn headerText="Author" dataField="author"/>
<mx:DataGridColumn headerText="Title" dataField="title"/>
<mx:DataGridColumn headerText="Genre" dataField="genre"/>
<mx:DataGridColumn headerText="Link" dataField="link"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="10" y="128" label="Get Query from Standard Remoting" width="100%" id="qry_btn" click=" qryService.getAllBooks();"/>
<mx:DataGrid id="wsdlDG01_dg" width="100%" height="120">
<mx:columns>
<mx:DataGridColumn headerText="Author" dataField="AUTHOR"/>
<mx:DataGridColumn headerText="Title" dataField="TITLE"/>
<mx:DataGridColumn headerText="Genre" dataField="GENRE"/>
<mx:DataGridColumn headerText="Link" dataField="LINK"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="10" y="128" label="Get Query from Web Service using MXML" width="100%" id="wsdl01_btn" click=" wsdlQryService.getAllBooks();"/>
</mx:VBox>
<mx:Form x="0" y="310" width="100%" id="infoForm">
<mx:FormHeading label="Enter values into the form."/>
<mx:FormItem label="Author Name">
<mx:TextInput id="bookAuthor" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Title">
<mx:TextInput id="bookTitle" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Genre">
<mx:TextInput id="bookGenre" width="100%"/>
</mx:FormItem>
<mx:FormItem label="URL">
<mx:TextInput id="bookLink" width="100%" />
</mx:FormItem>
<mx:FormItem label="">
<mx:Button id="form_btn" label="Submit Form" width="100%" click="submitBook();"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:VBox>
</mx:Application>
__._,_.___
--
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
Web site design development | Computer software development | Software design and development |
Macromedia flex | Software development best practice |
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.
__,_._,___