
871
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
•
You use the
setReturnFormat
function to specify whether to return the result in JSON format (the default), in
WDDX format, or as plain text. Use the
setQueryFormat
function to specify whether to return a JSON format
query as an object with an array of column names and an array of row arrays, or as an object that corresponds to
the WDDX query format. These functions only effect the format of data returned by ColdFusion. Data sent from
the proxy to the server is always in JSON format.
Submitting data to a CFC
When you use an Ajax CFC proxy, you send to the CFC function any client-side data that can be serialized to JSON
format, not just form data. However, the proxy cannot serialize DOM tree elements because they are wrappers on
native code. Therefore, you cannot use DOM tree elements directly as parameters to a CFC function that you call by
using an Ajax proxy. To ensure correct serialization to JSON for sending to the CFC, use basic JavaScript types only:
array, object, and simple types. Instead of using a DOM element directly, you pass only the specific element attributes
that you require to the CFC function, either individually or in an array or object.
When you use the
cfc
attribute, you submit form data to the CFC without refreshing the client page by calling the
proxy
setForm
function before you call a CFC proxy function in your JavaScript. The proxy function then passes all
field values of the specified form to the CFC function. In the CFC function Arguments scope, the argument names are
the form control
ID
attributes (or, by default, the
name
attributes) and the argument values are the control values.
Note:
You cannot use the
setForm
function to submit the contents of file fields.
To pass the form parameters to your proxy function, invoke the proxy function immediately after you call the
setForm
function. Subsequent proxy function invocations do not get the form parameters.
If you also pass arguments explicitly to the CFC,
cfargument
tags in the CFC function that specify the explicitly passed
arguments must precede any
cfargument
tags for the form fields. For example, if you have the following submitForm
JavaScript function:
function submitForm() {
var proxy = new remoteHandler();
proxy.setCallbackHandler(callbackHandler);
proxy.setErrorHandler(errorHandler);
proxy.setForm('myform');
proxy.setData('loggedIn');
}
In this example, the remoteHandler.cfc setData function starts as follows:
<cffunction name="setData" access="remote" output="false">
<cfargument name="loggedIn">
<cfargument name="userName">
...
In this example,
userName
is the name of a form field. If the
cfargument
tag for
userName
preceded the
cfargument
tag for the
loggedIn
explicitly passed variable, the CFC function would not get the value of
loggedIn
. Your CFC
function can omit
cfargument
tags for the form fields.
Example: Using an asynchronous CFC proxy
The following example uses a remote CFC method to populate a drop-down list of employees. When you select a name
from the list, it uses a call to the CFC method to get information about the employee, and displays the results.
The main application page has the following lines:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...