Ask a Jedi: How do I insert Spry data into a ColdFusion variable?

Rual asks:

I tried a search on your blog and on the LiveDocs of Spry for how to insert Spry data into a ColdFusion variable, currently is trowing an error this expression. #LsDateFormat({FECHANACIMIENTO}, "dd/mm/yyyy")# Gives this error
Invalid CFML construct found on line 35 at column 50. ColdFusion was looking at the following text: { Thanks for your time and help. The line 35 is the line pasted above. I am using JSON and the data outputs fine it just errors out when I insert it into a ColdFusion function.

This is a rather simple problem - and I have a feeling we are going to see many questions like this. Now that CF8 makes Ajax easy (as does Spry), some of the “old” questions begin to crop up.

The short answer is that you have a basic misunderstanding. Spry is completely client side. It uses Ajax to request data and then renders it on your browser client. ColdFusion is entirely server side.

Think of it like this:

  1. User requests a page.
  2. Web server hands off the request to ColdFusion.
  3. ColdFusion processes the page and returns HTML (rendered text) to the web server.
  4. Web server returns the simple text back to the browser.
  5. The browser begins to render the HTML.
  6. Spry runs what it has to do - including making new HTTP requests to load XML/JSON/HTML type data.
  7. It then uses JavaScript to rewrite content on screen. </ol> As you can see - Spry (and any other JavaScript framework) comes into play after ColdFusion is out of the picture. Now if you simply wanted to format date data... heh, well, that's kind of fun. Spry does support firing JavaScript events before rendering. This would let you modify a column of data before it is displayed. See this sample and this blog entry for some examples. The real trouble you run into is the formatting.
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments