Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1094

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Validating WDDX data
The
tag has a
cfwddx
Validate
set this attribute to True, the XML parser uses the WDDX DTD to validate the WDDX data before deserializing it. If
the WDDX is not valid, ColdFusion generates an error. By default, ColdFusion does not validate WDDX data before
trying to convert it to ColdFusion or JavaScript data.
The
function returns True if a variable is a valid WDDX data packet. It returns False otherwise. You can use
IsWDDX
this function to validate WDDX packets before converting them to another format. For example, you can use it instead
of the
attribute, so that invalid WDDX is handled within conditional logic instead of error-handling
cfwddxvalidate
code. You can also use it to pre-validate data that JavaScript at the browser deserializes.
Using JavaScript objects
ColdFusion provides two JavaScript objects,
in JavaScript to convert data to WDDX. These objects are defined in the file webroot/cfide/scripts/wddx.js.
The CFML Reference describes these objects and their methods in detail. The example
browser to the
server" on page 1090 shows how you can use these objects to serialize JavaScript to WDDX.
Converting CFML data to a JavaScript object
The following example demonstrates the transfer of a
server to a JavaScript object that is processed by the browser.
The application consists of four principal sections:
• Running a data query
• Including the WDDX JavaScript utility classes
• Calling the conversion function
• Writing the object data in HTML
The following example uses the cfdocexamples data source that is installed with ColdFusion:
<!--- Create a simple query --->
<cfquery name = "q" datasource ="cfdocexamples">
SELECT Message_Id, Thread_id, Username, Posted
FROM messages
</cfquery>
<!--- Load the wddx.js file, which includes the dump function --->
<script type="text/javascript" src="/CFIDE/scripts/wddx.js"></script>
<script>
// Use WDDX to move from CFML data to JavaScript
<cfwddx action="cfml2js" input="#q#" topLevelVariable="qj">
// Dump the recordset to show that all the data has reached
// the client successfully.
document.write(qj.dump(true));
</script>
Note: To see how
cfwddx Action="cfml2js"
wwwroot/myapps/wddxjavascript.cfm, run the page in your browser and select View Source in your browser.
attribute that you can use when converting WDDX to CFML or JavaScript. When you
WddxSerializer object
cfquery
works, save this code under your web root directory, for example in
Last updated 1/20/2012
and
WddxRecordset object
"Transferring data from the
recordset from a ColdFusion page executing on the
1089
, that you can use

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents