Notes: Advanced CFEclipse

Presented by Mark Drew.

CFEclipse was started by Rob Rohan in 2003. Mark joined in 2004. Macromedia endorses it in 2005, and was bought by Adobe he joined the Eclipse Foundation. Flex Builder was built on Eclipse in 2006, and added the RDS plugin for Eclipse. And CFEclipse 1.3 has been released in 2007.

Eclipse automatically gives us cross-platform capability, version control (with CVS), Ant task runner, a generic text editor, a built-in web browser, search, and more. CFEclipse sits on top of this functionality.

CFEclipse gives us tag completion, syntax highlighting, outline view of code, methods view, web help, snippets. It has a file explorer view for those of us who like the HomeSite style of editing files. Scribble pad for quick code testing. Multiple syntax libraries (to support BlueDraon, Railo, etc), toolbars like HomeSite, component explorers, variable insight.

Snippets

Can create snippets to effectively “paste in” code you may use over and over again. Hit Ctrl-J or Cmd-J to pull up a snippet after typing the trigger text. Can have snippet variables to insert custom code when pasting the snippet.

<mycode>$${MyCustomVar}</mycode>, for example, will insert what you put in msgbox when it asks for that variable. You can also define default values. For instance, $${MyCustomVar:The default value} will put “The default value” in there.

Development Patterns and Support

The typical Eclipse project paradigm is for local development. Working in the Eclipse workspace and probably use Subversion.

Otherwise, can use “File Location” or “FTP/SFTP” locations to directly edit some text that is somewhere outside your workspace, either on another machine, a file share, etc.

Ant

Ant scripts are typically called build.xml. When in the build.xml file, hit Ctrl-Space to get a build file template. You can then just work on the template.

Ant builds are “Target” oriented. They are basically collections of tasks that can be accomplished. A target can have a depends=”" attribute that will not run until another target is executed. You can then use commands to copy files, zip files, etc. For instance, <copydir>, <mkdir>, <input>, <echo>, <svn>, <ftp>, etc.

Good articles on Ant with SQL Scripts, Ant with Subversion, and Ant with FTP.
Unit Testing

A CFUnit plugin just had a soft release at CFUnited! Supports both CFUnit and cfcUnit. With it, you can do unit testing from right within Eclipse rather than going to a web page and doing it. Sweeeet!

Framework Explorer

Just like there is a CFC explorer, there is a framework explorer. When you open the view in your project, it will automatically figure out what frameworks you’re using, it will show them, and you can open them up and see your beans and other various components of your frameworks. Sweeeeet!

SnipEx

Can have snippets that are stored on a central server.

Notes: LiveCycle Data Services

LiveCycle Data Services used to be separate from CF. Now they are together, so you don’t have to configure the RMI to have them talk to each other.

With it, using AS3 and Flash Remoting, you can do stuff like invoke CFC methods from within ActionScript!  No Flex server is involved.

Messaging. Publish and subscribe. I say hello and everyone will listen to me. Someone says goodbye and I hear, and know not to talk to them anymore. ColdFusion can be both a Producer and a Consumer. Publish with sendGatewayMessage() and subscribe with an event gateway CFC.

New in CF8? Faster. Now uses Java API instead of that RMI.  Starting with CF8, it is included right in the CF installer. An express version comes right with CF8.

Not many notes on this, I wasn’t following too closely since we won’t be getting LCDS, at least not until I’m more heavy into Flex.

Notes: Working With RSS in CF

Presented by Pete Freitag.

Really Simple Syndication. Just an XML file. Like WDDX: They're both syndication structures. But RSS is a defined structure, so it makes it easier to consume because you know exactly what the standards should be for it.

Studies have shown that 69% of those surveyed don't use RSS, 27% are unaware of it, but use RSS, and 4% are aware RSS users. So about 1/3 of population use RSS, but it has successfully evaded technical knowledge requirements for people to use it. RSS feed is one file (called a channel) with multiple articles (called items).

Why publish RSS? Can increase traffic; people subscribed will return to your site when their reader notifies them that new info is available. Also more convenient for your readers. What are the downsides? Easier to steal your content when it is in a prestructured RSS feed. Can actually increase your bandwidth too, because readers may check your feed every hour or something.

How used? Portals like Google Homepage, RSS readers (desktop apps, Google Reader), Aggregators (like MXNA, Fullasagoog), RSS to email. Not just for blogs; can be used for news articles, forums, newsletters.

RSS vs. ATOM. RSS 2.0 is simple and gets the job done. ATOM is more complex with some add'l features. Typically, the add'l features are not used. For instance, you can post multiple versions for different content types (e.g. plaintext vs. HTML).

Generating an RSS Feed

Start by resetting any content. Then immediately do the XML header because it MUST be on the first line.

CFM:
  1. <cfcontent reset="true"><?xml version="1.0" ?>
  2. <cfheader name="Content-Type" value="text/xml">

Nice thing about setting it to "text/xml" is it will actually display the XML when opening in the browser. Nice for viewing the results. Can also choose "application/RSS+XML".

XML:
  1. <rss version="2.0">
  2.   <channel>
  3.     <title>My News Feed</title>
  4.     <description>This is my news feed!</description>
  5.     <language>en-us</language>
  6.     <lastBuildDate>Wed, 27 Jun 2007 16:46:00 GMT</lastBuildDate>
  7.     <item>
  8.       <title>This Article Title</title>
  9.       <link>http://you.com/news.cfm?id=1</link>
  10.       <description>My article content.</description>
  11.       <pubDate>Wed, 27 Jun 2007 16:46:00 GMT</pubDate>
  12.       <guid>http://you.com/news.cfm?id=1</guid>
  13.     </item>
  14.   </channel>
  15. </rss>

Dates in RSS feed must be RFC 822 compliant. Use the GetHttpTimeString() function to display it in the proper format.

So, when doing this with <cfquery>/<cfoutput>, you might do something like:

CFM:
  1. <rss version="2.0">
  2.   <channel>
  3.     <title>My Feed</title>
  4.     <description>My feed description.</description>
  5.     <language>en-us</language>
  6.     <lastBuildDate>#GetHttpTimeString(Now())#</lastBuildDate>
  7.     <cfoutput query="myArticles">
  8.       <item>
  9.         <title>#myArticles.Title#</title>
  10.         <link>http://you.com/news.cfm?id=#myArticles.ID#</link>
  11.         <description><![CDATA[#xmlFormat(MyArticle.Story)#]]></description>
  12.         <pubDate>#GetHttpTimeString(myArticles.DT)#</pubDate>
  13.         <guid>http://you.com/news.cfm?id=#myArticles.ID#</guid>
  14.       </item>
  15.     </cfoutput>
  16.   </channel>
  17. </rss>

Send your feed to feedvalidator.org to see if it is valid. Helps you get your feed up and running.

You can also use enclosures, which is most used for podcasting. It's like an "attachment" to your feed. Technically, you can only have one enclosure. It may allow multiple enclosures, but because you're not supposed to, this can be problematic.

XML:
  1. <enclosure url="http://you.com/audio.mp3" length="12345" type="audio/mpeg" />

Length is in bytes. Can obviously be more than just audio files. Could be a Word or PDF file.

Can also add a <category> tag within the <item> tag. Can add multiple tags. Technorati bases its "tags" on these categories in RSS feeds. Can also add <author> (must be an email). Can also add <source>, where it refers to a source article you may be writing about or rebutting.

More <channel> tags:

  • copyright: Copyright notice.
  • ttl: Time to live. Number of minutes to cache the feed.
  • image: Include an image for the RSS feed.
  • skipDays: Listing of days that the feed will not change.
  • skipHours: Listing of hours where the feed is not changed.

Can see the RSS 2.0 spec for more info.

Feeds in ColdFusion 8

The new <cffeed> tag can create AND parse RSS feeds.

CFM:
  1. <cffeed action="create"
  2.         name="#feed#"
  3.         outputfile="rss.xml"
  4.         overwrite="true"
  5.         xmlVar="xmlout">

Name will be a struct with the content. xmlVar allows you to put the generated RSS XML into a variable instead of the file.

So create a struct that contains title, description, link, and item which would be an array of structs with the various item elements (title, description, pubDate, link). This way, you can work with familiar ColdFusion structs and arrays when generating this stuff, then just feed it all to <cffeed>.

Parsing feeds is pretty easy.

CFM:
  1. <cffeed action="read"
  2.         source="http://you.com/rrs/"
  3.         query="feed"
  4.         properties="feedMetaData">

feedMetaData will be the general channel metadata, and the feed variable from the query="" attribute will be a query form of the items.

Problem with the returned query is that it returns a million columns, and the columns you need to use are different for ATOM vs. RSS. It would be nice if there was one common set of fields that are set depending on whether the feed is ATOM or RSS.

So if using RSS, you may do something like:

CFM:
  1. <h1><cfoutput>#feedMetaData.title#</cfoutput></h1>
  2. <cfoutput query="feed">
  3.   <h2><a href="#feed.rsslink#">#feed.title#</a></h2>
  4.   <p>#feed.description#</p>
  5. </cfoutput>

So <cffeed> is really nice, although problematic due to the different ways it handles ATOM vs. RSS feeds. This isn't really their fault, but it would be nice if there was a black box that took care of the translation between the two feeds.

Notes: Ajax Development with ColdFusion Frameworks

Presented by Joe Rinehart.

What's Ajax? 

Classically, it means "Asynchronous JavaScript and XML", although also used with JSON a lot. For today, it will mean "using JavaScript to update a portion of an already displayed page without reloading."

So, for an example: Deleting a single record is so server-heavy. Make the request, delete the record, then reget the list, and rerender the entire list page. In Ajax, we now make the request, the server just deletes the record and sends a small token indicating that it did it.

So we balance the load between the client and the server more efficiently.  It also doesn't interrupt the experience for the user.  And the experience is just richer in general.

"Unstructured Ajax". Calls made to the server don't return data, they return pre-rendered HTML. Very easy to implement, doesn't require major changes in architecture towards service layers. All we need are some scripts that generate HTML!

But you have now bound your data and presentation together. Isn't flexible for changing. Similarly, Ajax request "handlers" on the server side tend to be very single-purpose. They are used for that specific Ajax call and can't do much else.

"Structured Ajax". Not just replacing regions of screen with the response. Instead, you're taking XML, JSON, or even perhaps delimited lists of strings and using the pure data. No intermingling with presentation. Thus, it will work better with service layers that are focused on data, not presentation. What if you want to update two regions of the page, for instance? Unstructured Ajax would get messy that way, but when returning just data, you can do this.

This is more difficult to implement though. Need extensive knowledge of JavaScript and DOM. And what do you use for your structured data? XML? SOAP? JSON?

When it comes right down to it though, both types use the same technology, the XmlHttpRequest. Just creating this object is troublesome. Very different from one browser to the other. This is where nice JavaScript libraries come in. CFAjax, Spry, Dojo, AjaxCFC, Prototype + Scriptaculous. But there are others! Zoop, Plex, Rico, sajax, MochiKit, Taco, MagicAjax, Microsoft Atlas, yada, yada, yada.

So we will use Prototype and Scriptaculous in this example.

Implementing Ajax with Model-Glue

For today, we'll just do unstructured Ajax. Not the best, but a great way to get started in this demo. Will be faster for demoing.

Prototype. Great, and easy for unstructured Ajax, all on its own. Wraps around the XmlHttpRequest calls. It does have structured Ajax features, but it's custom to Prototype.

Scriptaculous. An "add-on" to Prototype. Provides effects, drag-and-drop, unit testing.

Model-Glue. Framework for developing HTML-based apps that use CFCs for business logic.

Model-Glue can work seamlessly with these Ajax frameworks. Can return some HTML which Prototype will put in a region via unstructured Ajax.

The example app is a list of tasks. You can create, edit, complete, and delete tasks.

What can we Ajaxify? Delete existing items. Add more tasks. Inline item editing.

Ajax Delete. Create an event handler that deletes a task but returns nothing. Then, include our Ajax frameworks and add some JavaScript to call the event handler in an asynchronous manner. Third, use scriptaculous to make the row fade out. Finally, a few more visual clues.

With a two-line delete function in JavaScript, you make the Ajax request and then fade the row with Scriptaculous.  The Ajax request will just call a Model-Glue event that uses the built-in Model-Glue generic database management to delete the record in the database.

First create the MG event, then write the Prototype code to make the Ajax.request(), then write the Scriptaculous code to give visual feedback.

A big problem with Ajax is that it is harder to debug. Use cfcUnit for testing the CFCs. You should do this anyway. It's a lot easier to run unit tests than to put fake data in your forms and seeing what happens, over and over again. On the client side, debug with FireBug! But beyond that, do your client-side testing, even testing DOM results, with Selenium. With cfcUnit and Selenium, you can walk your way up the tiers to see where the errors occurred.

ColdSpring. With it, you can expose existing components as they are to be services for Ajax.  Google "Remote Proxy ColdSpring" to read some articles by Chris Scott on this. ColdSpring will effectively generate the facades for you! Very service-oriented approach and requires no extra code.

  Theme Brought to you by Directory Journal and Elegant Directory.