I would like to pass complex structures via the URL. I know this can be done
using hidden fields in forms but sometimes, I need to pass data from a file
that is not a form. I'm having problems getting this to work. I have a really
simple file that sets up a structure, serializes it using wddx and then
attempts to pass the serialized structure from a hyperlink. The file that is
called de-serializes the structure and tries to access it. I'm getting an
error:
WDDX packet parse error at line -1, column -1. Premature end of file..
on the de-serialization line. I know that things are serialized/de-serialized
correctly because if I serialize and then deserialize in the same file (without
passing it to another file via URL), I can access it fine.
Is it possible to send WDDX packets to another cfm file via the URL?
Here is my simplified code:
dsp_testPage.cfm
-------------------------
<cfset relatives=StructNew()>
<cfset relatives.field1 = "Dad">
<cfset relatives.field2 = "Mom">
<cfset relatives.field3 = "Sister">
<cfset relatives.field4 = "Brother">
<cfwddx action="cfml2wddx" input="#relatives#" output="wddxRelatives">
<br>
<a href="./index.cfm?fuseaction=test&relatives=#wddxRelatives#">Click Here</a>
--------------------------------------------------------------------------------
------------------------------------
Then I have another page called index.cfm (I'm using fusebox) that looks like
this:
<html>
<head></head>
<body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0"
rightmargin="0" bgcolor="#FFFFFF">
<cfparam name="attributes.fuseaction" default="home">
<cfswitch expression="#attributes.fuseaction#">
<cfcase value="home">
<cfinclude template="./dsp_DISPLAY/dsp_TESTPage.cfm">
</cfcase>
<cfcase value="test">
<cfwddx input="#attributes.relatives#" action="WDDX2CFML"
output="localAppData">
<cfoutput>
<br>Inside Test<br><br>
field1 = #localAppData.field1#<br>
field2 = #localAppData.field2#<br>
field3 = #localAppData.field3#<br>
field4 = #localAppData.field4#<br>
</cfoutput>
</cfcase>
</cfswitch>
</body>
</html>
cf_dev2 - 28 Aug 2007 21:22 GMT
duplicate of
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=1&catid=3&t
hreadid=1296499&enterthread=y
nummsa - 28 Aug 2007 21:29 GMT
If you want to keep using WDDX, you must encode the GET string using the
URLEncodedFormat function. i.e.
<a
href="./index.cfm?fuseaction=test&relatives=#URLEncodedFormat(wddxRelatives)#">
Click Here</a>
I would investigate using JSON instead seeing as it is a lot less characters
to send in a URL GET string. WDDX will make the string grow very fast.
If you want JSON and are on CFMX7, search for the CFJSON class. If you're on
CFMX8, just use the SerializeJSON function.
beckyjmcd - 28 Aug 2007 21:42 GMT
I added the URLEncodedFormat and a corresponding URLDecode but I still get the error
WDDX packet parse error at line -1, column -1. Premature end of file..
I will also look into JSON.
nummsa - 28 Aug 2007 21:51 GMT
I would honestly go with JSON instead.
To dig further into the WDDX, on the receiving end just prior to the WDDX2CFML
- try outputting the WDDX string with CFOUTPUT and the HTMLCodeFormat function
so that you can read it. Make sure the WDDX packet starts with something of the
like:
<wddxPacket version='1.0'><header/><data>
and ends with something of the like:
</data></wddxPacket>
beckyjmcd - 28 Aug 2007 22:10 GMT
Really silly mistake. In the file where I create the href link, I need to
place this inside a <cfoutput> tag in order for the variable to be passed on
the URL. It is working fine now that I hadded the <cfoutput>.
I will continue to investigate JSON but I really need my app to be independent
of Javascript (able to work when Javascript is turned off) so it may not be the
best option for me.
Thank You.
nummsa - 28 Aug 2007 22:22 GMT
I still think JSON is a multitude more optimal for what you are trying to
accomplish. It's a much more optimized (from a number of characters standpoint)
serialization method than WDDX which is bloat in my opinion. It really has
little to do with Javascript to be honest - and as it is implemented in
Coldfusion it is just a way to serialize, that is all. No dependence on
Javascript at all.
Good to hear it's working!
beckyjmcd - 28 Aug 2007 22:24 GMT
If the user is not required to have Javascript turned on in their browser, then I can use it. I'm going to get what I have working with wddx but I will definitely explore JSON.
Thanks!!
nummsa - 28 Aug 2007 22:43 GMT
You missed the point, you can serialize Colfdusion Data in JSON without any
Javascript. This means that if the user is using a javascript disabled web
browser, it will still work. All the JSON serialization, as well as WDDX
serialization happens on the server side.
Here's a CFJSON class I've used:
http://www.epiphantastic.com/cfjson/