Changes between Version 1 and Version 2 of HowTos/HowToUseRemoting

Show
Ignore:
Timestamp:
11/16/09 23:54:26 (16 years ago)
Author:
cfgrok (IP: 64.30.223.5)
Comment:

Renamed page for alpha sorting on home page -- cleanup up formatting issues

Legend:

Unmodified
Added
Removed
Modified
  • HowTos/HowToUseRemoting

    v1 v2  
    1 = How To Use Remoting = 
     1= Remoting = 
    22 
    33== History == 
     
    1010== The Basics == 
    1111 
    12 The process is simple. Model-Glue 3 has a component called "!RemotingService.cfc" that sits in the root of your project folder and uses cfmodule to run the index.cfm file of your application. The !RemotingService extends !ModelGlue.gesture.remoting.!AbstractRemotingService which provides one function: executeEvent(). When you call !RemotingService.executeEvent(...), the remoting service uses a handle on the ModelGlue instance in the application scope to run the event and then extracts values you've asked for from the Event object into a struct which is then returned to your remoting client. And because of how this is all implemented, it can be used either via a Flex !RemoteObject, directly, or as a web service. This makes it possible for Flex, AJAX, and HTML applications to all make use of common functionality.  
     12The process is simple. Model-Glue 3 has a component called "!RemotingService.cfc" that sits in the root of your project folder and uses cfmodule to run the index.cfm file of your application. The !RemotingService extends !ModelGlue.gesture.remoting.!AbstractRemotingService which provides one function: executeEvent(). When you call !RemotingService.executeEvent(...), the remoting service uses a handle on the !ModelGlue instance in the application scope to run the event and then extracts values you've asked for from the Event object into a struct which is then returned to your remoting client. And because of how this is all implemented, it can be used either via a Flex !RemoteObject, directly, or as a web service. This makes it possible for Flex, AJAX, and HTML applications to all make use of common functionality.  
    1313 
    1414== Some basic rules regarding the !RemotingService.cfc == 
     
    1616Regardless of any other factor, the CFC in question must follow two rules: 
    1717 
    18 1. It must live in the root folder of a Model-Glue application. This is because it relies on the presence of an instane of !ModelGlue.cfc in the application scope to locate and run any events. It can have any name but it has to be in the root of the application. 
     181. It must live in the root folder of a Model-Glue application. This is because it relies on the presence of an instance of !ModelGlue.cfc in the application scope to locate and run any events. It can have any name but it has to be in the root of the application. 
    19191. It must extend modelglue.gesture.remoting.!AbstractRemotingService. This base class provides essential functionality (such as locating the Model-Glue instance in the application scope regardless of the name of the variable containing it).  
    2020 
     
    2929The code for this CFC 
    3030{{{ 
    31 #!xml 
    32         <cfcomponent output="false"> 
    33             <cfset variables.instance = StructNew()/> 
    34  
    35             <cffunction name="init" access="public" output="false" returntype="Users"> 
    36                 <cfreturn this/> 
    37             </cffunction> 
     31    <cfcomponent output="false"> 
     32        <cfset variables.instance = StructNew() /> 
     33 
     34        <cffunction name="init" access="public" output="false" returntype="Users"> 
     35            <cfreturn this /> 
     36        </cffunction> 
    3837 
    3938        <cffunction name="getUsers" access="remote" output="false" returntype="any"> 
    40             <cfset var local = StructNew()/> 
    41             <cfset local.myQuery = QueryNew("name","varchar")> 
     39            <cfset var local = StructNew() /> 
     40            <cfset local.myQuery = QueryNew("name","varchar") /> 
    4241            <cfloop from="1" to="12" index="local.j"> 
    43                 <cfset QueryAddRow(local.myQuery, 1)> 
    44                 <cfset QuerySetCell(local.myQuery, "name", "Person-#local.j#", local.j)> 
     42                <cfset QueryAddRow(local.myQuery, 1) /> 
     43                <cfset QuerySetCell(local.myQuery, "name", "Person-#local.j#", local.j) /> 
    4544            </cfloop> 
    46             <cfreturn local.myQuery/> 
     45            <cfreturn local.myQuery /> 
    4746        </cffunction> 
    4847 
     
    5655The code for !GetController.cfc is.. 
    5756{{{ 
    58 #!xml 
    5957    <cfcomponent output="false" beans="Users" extends="ModelGlue.gesture.controller.Controller"> 
    6058 
     
    7270}}} 
    7371 
    74 Notice here, we are using the new Model-Glue 3 feature called "bean injection". The controller has a scope called "beans" which contains an instance of our Users.cfc class. For this to work properly, you need to define the Users.cfc bean in the Coldspring.xml file like so.. 
    75  
    76 {{{ 
    77 #!xml 
     72Notice here, we are using the new Model-Glue 3 feature called "bean injection". The controller has a scope called "beans" which contains an instance of our Users.cfc class. For this to work properly, you need to define the Users.cfc bean in the !ColdSpring.xml file like so.. 
     73 
     74{{{ 
    7875    <bean id="Users" class="mapping_to_your_app.model.Users"/> 
    7976}}} 
     
    8481 
    8582{{{ 
    86 #!xml 
    87         <controller id="!GetController" type="mapping_to_your_app.controller.!GetController"> 
     83        <controller id="GetController" type="mapping_to_your_app.controller.GetController"> 
    8884            <message-listener function="users" message="get.users" /> 
    8985        </controller> 
     
    9389 
    9490{{{ 
    95 #!xml 
    9691        <event-handler name="get.users"> 
    9792            <broadcasts> 
     
    108103 
    109104{{{ 
    110 #!xml 
    111105<cfdump label="My Users" var="#event.getValue("users")#"> 
    112106}}} 
     
    124118== A couple of Important Things to Note about using Flex Remoting: == 
    125119 
    126 1. If you have a /!ModelGlue mapping (via either Application.cfc or the ColdFusion Administrator), Flash Remoting will not work until you have edited {cfusion_home}/wwwroot/WEB-INF/flex/remoting-config.xml (on J2EE or multiserver, it's inside {jrun_home}/servers/cfusion.ear/cfusion.war/WEB-INF/flex/remoting-config.xml). You have to find the setting <use-mappings>false</use-mappings> and change it to true. Then restart your CF server. Until you've done this, calls to MG remoting from Flex applications will fail due a file not found. This only applies to Flex applications making remoting calls through the !FlashRemoting gateway. 
     1201. If you have a /!ModelGlue mapping (via either Application.cfc or the !ColdFusion Administrator), Flash Remoting will not work until you have edited {cfusion_home}/wwwroot/WEB-INF/flex/remoting-config.xml (on J2EE or multiserver, it's inside {jrun_home}/servers/cfusion.ear/cfusion.war/WEB-INF/flex/remoting-config.xml). You have to find the setting <use-mappings>false</use-mappings> and change it to true. Then restart your CF server. Until you've done this, calls to MG remoting from Flex applications will fail due a file not found. This only applies to Flex applications making remoting calls through the !FlashRemoting gateway. 
    127121 
    1281221. For the application to work properly, it will need to understand the remoting destination and endpoints. There are a number of ways to handle this, this is the simplest. In the Flex project properties in Flex Builder, go to Flex Compiler and add the following to the Additional Compiler Arguments" 
     
    135129 
    136130{{{ 
    137 #!xml 
    138131<?xml version="1.0" encoding="utf-8"?> 
    139132<mx:Application 
     
    172165</mx:Application> 
    173166}}} 
     167 
    174168We define our Remote Object service with the "mx:RemoteObject" tag. In this tag, we called the standard "!ColdFusion" service defined in your remoting-config.xml in your flex folder on the !ColdFusion server. The source defines the specific cfc we will are calling which in with our MG3 app will always be the !RemotingService.cfc. When the result comes back, we have a function called "resultHandler()" which will process the data. 
    175169 
     
    185179 
    186180== AJAX Example with jQuery == 
     181 
    187182jQuery is a popular Javascript library for building Rich Internet Applications. We're not going explain all the features of jQuery here, but this simple example will explain how it can be used to call the MG3 remoting service. As before, we'll go ahead and see the entire code and then go through it's operation. 
    188183 
    189184The following code is a single html file. 
    190185{{{ 
    191 #!xml 
    192186<script type="text/javascript" src="js/jquery.js"></script> 
    193187