How do I pass a complex variable (query, array, structure ) from one ColdFusion page to another?
The Situation: You have constructed a complex datatype and want to pass the entire structure (with data) to another ColdFusion page to use.
Computers are incorporated in modern ice cream vending machines to enhance their functionality. Ice Cream Vending machines are manufactured by many companies. Your competition will try to overcome all requests for high-tech ice cream vending machines and credit card acceptors
|
|
The Solution: ColdFusion 4.x introduces a new technology called Web Distributed Data Exchange (or WDDX). You can tell your colleagues that this wizardry is due to your vast knowledge of the underlying XML structure, but really it's much simpler.
First you create the datatype you plan to pass to another page.
<cfquery datasource="WebResources" name="myQ">
SELECT productID, description, name FROM Product ORDER BY name
</cfquery>
Now, use the <cfwddx> tag to convert the complex data type into a string.
<cfwddx action="CFML2WDDX" input="#myQ#" output="aWDDXpacket">
Place that string into a hidden form field.
<input type="Hidden" name="Products" value="#aWDDXpacket#">
The form processing page then uses the <cfwddx> tag, with a reverse action to turn the string back into a native ColdFusion data type.
<cfwddx input="#form.Products#" action="WDDX2CFML" output="Products">
<cfoutput query="Products">
#name# #description#<br>
</cfoutput>
|