cfwddx


<cfwddx>

To turn the preceding code example into a WDDX packet, you can use a tag called <cfwddx>, like this:

 <cfwddx action="CFML2WDDX"         input="#products#"         output="NewPacket"> 

CAUTION

Note the pound signs (#) around the value for the input attribute. If you forget them, ColdFusion thinks you are trying to serialize the literal string products.


Table 35.1 lists the attributes of the <cfwddx> tag.

Table 35.1. <cfwddx> Attributes

ATTRIBUTE

DESCRIPTION

action

Tells ColdFusion what action to take on the variable

input

Tells ColdFusion which variable to serialize

output

Names the variable into which ColdFusion will place the packet

toplevelvariable

If you are using WDDX to create JavaScript, this is the name of the JavaScript variable being created


Table 35.2 lists the possible values for the action attribute.

Table 35.2. Values for the action Attribute

VALUE

DESCRIPTION

cfml2wddx

Serializes ColdFusion data into a WDDX packet

wddx2cfml

Deserializes the ColdFusion data from a WDDX packet to ColdFusion data

wddx2js

Deserializes a WDDX packet into native JavaScript

cfml2js

Turns ColdFusion data directly into JavaScript data using WDDX as a bridge


NOTE

JavaScript and ColdFusion are only two of the languages that understand WDDX. Some others are PHP, Perl, ASP, Python, and Java.


If you have a query record set called GetStates and want to serialize it into a WDDX packet, you can type:

 <cfwddx action="CFML2WDDX"         input="#GetStates#"> 

Because the preceding <cfwddx> code doesn't have an output attribute, the data is output directly to the page itself rather than being put into a variable.

CAUTION

WDDX packets don't like special characters such as < or > outside the XML tags. When you're developing applications, you probably have the ColdFusion debugging settings turned on in ColdFusion Administrator. The debugging is displayed at the bottom of your HTML page using HTML code. This means that when your WDDX packet is written to the page, it becomes corrupted by the extra HTML debugging information.

To deal with this problem, always place the tag <cfsetting showdebugoutput="No"> at the top of your page. It suppresses debugging on the page.


TIP

Two ColdFusion functions that are helpful for creating valid WDDX packets are XMLFormat() and IsWDDX(). The former converts special characters in data to an acceptable XML format. The latter verifies that the WDDX packet is valid.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net