fusiongrokker

Entries Tagged as AJAX

AJAX in ColdFusion 8: Don’t overthink it!

For CFMenuCal, I'm planning on using AJAX to display a "settings" type window, which will allow you to edit your meal data, allowable proximities, and other settings. To teach myself the basics of CFAjaxProxy and get a better idea of how to write my components to that end, I made a simple page that dumps the session scope, and has a form with a textbox and submit button that should - in theory - make the AJAX call to my test component, which will then update the session scope.

I know this sounds pretty simple, and in actuality, it is. But I spent at least a couple of hours on Saturday reading up on JSON, and thinking about how I'll need to implement it. I was thinking I would need to serialize my data on the client side, and then use DeserializeJSON() in my component to turn the JSON string into CF variables. As it turns out - that was wasted time. It's all done implicitly for you.

So first, let's build our component:

<cfcomponent name="AjaxTest" hint="Performs some proof of concept AJAX functionality for CFMenuCal.">       <cffunction name="updateSession" access="remote" output="false" returntype="Boolean">         <cfargument name="data" type="any" required="true">         <cftry>             <cfset session.data = arguments.data>             <cfreturn true>             <cfcatch type="any">                 <!--- log the error via cfmail or cffile --->                 <cfreturn false>             </cfcatch>         </cftry>     </cffunction>   </cfcomponent>

Notice that the I set the ACCESS of the function to REMOTE. This pretty frequently gets me (I commonly use PUBLIC), and I spend too much time trying to figure out why I'm getting "method X doesn't have any properties" JavaScript errors.

So now that we have our component, we need a page that uses it. Enter test.cfm:

<cfajaxproxy cfc="com.AjaxTest">   <cfdump var="#session#" label="Session Scope">   <form method="post" name="fooForm">     <input type="text" name="bar" size="30" />     <input type="button" onClick="sessionize(this.form.bar.value);" value="Save" /> </form>   <script type="text/javascript" language="javascript">     sessionize = function(data){         var updater = new com.AjaxTest();         var myObj = {};           myObj.numberValue = 42;         myObj.stringValue = "hello, world!";         myObj.userValue = data;           var success = updater.updateSession(myObj);           if (success == "true" || success == true){             alert('Success! Refreshing the page to update dump...');             document.location.href = document.location.href;         }else{             alert('An error occurred. Check the log for details...');         }     } </script>

The above assumes the component is named AjaxTest and resides either in a subdirectory named "com" of the current directory, or of the root folder. Running it should produce a cfdump that looks something like this:

CFDump

The moral of the story is: Don't overthink it! The ColdFusion 8 team over at Adobe has made this too easy.

Posted in AJAX | CFMenuCal | ColdFusion | Scorpio July 17 2007

CFMenuCal: Configuration!

I just couldn't resist playing with all of the sexy AJAX tags and CFWindow. I couldn't. I can't play with new syntaxes and not the new tags. So I put aside working on side-dish proximity checking and instead worked on this beautiful screen:

CFMenuCal: Config Screen
Click to enlarge

There is plenty of functionality in there that doesn't work, or works incorrectly. But the skeleton is there, and you can get an idea of where I'm headed with it. The code has been committed to the repository, but the demo has not been updated. So if you're eager to see it up close and personal, check it out! (Literally!)

I promise I will work on side dish proximity next, so that I can go ahead and call it an alpha release.

Promise.

Posted in AJAX | CFMenuCal | My projects | Scorpio June 07 2007

Philly CFUG Scorpio Presentation

Of course there have been numerous blogs about features announced at other meetings (I liked this one, and this one, among many others) but tonight I attended our very own CFUG meeting, and not only that, it was my first.

Among all of the new tags and functionality announced, I think I'm most excited about the return of the debugger, the new image handling, the ability for CFLoop to natively parse files (by line, or by bytes), the server monitoring utilities, and of course the AJAX tags. I would have liked to have seen the debugger in action, but we were pushing 3 hours as it was with fairly few questions, and had to bail before they started drawing names to give away schwag (including a copy of Scorpio itself!), since my carpooling buddy was out passed his curfew.

The CFPDF tag set looks interesting and very useful, but my current clients don't do a whole lot with PDFs and my past clients only made limited use of PDF forms. I can see that it has great potential, but I don't see myself putting it to great use for a while.

One thing that this has reminded me of, for sure, is that I have become very comfortable inside my box. For the most part, the things that I've been developing could run just fine on CF5. (I blame the customer!) I have come away from the meeting inspired to learn some of the great things that MX7 made available, but at the same time, I feel like I'm already spoiled and have absolutely no motivation to try and learn AJAX "the hard way." Why should I bother, when I've seen how easy it will be in just a few short months?

I'm not sure how much of this has already been announced, but here's a list of stuff that caught my attention enough for me to write down:

Posted in AJAX | CFUG | ColdFusion | Scorpio May 15 2007