dans.blog


The miscellaneous ramblings and thoughts of Dan G. Switzer, II

My Spring <br /> 2007 jQuery Presentation

I wanted to post my presentation files for the demo I'll be giving at Spring <br /> Conference 2007 tomorrow morning. This file contains the Powerpoint Presentation, plus all the example file (plus some that I probably won't have a time to get to!)

I probably went overboard on the examples—I seriously doubt I can get through them all in 60 minutes, but hopefully you'll find the source code commented well enough that even if you don't set through my presentation, you can still follow what's going on.

Download "Down & Dirty with jQuery" Presentation

more…


Sending e-mail attachments in CFMX without writing data to disk

One of the many projects I'm currently working on is some code to delay sending of e-mails until a specified window of time. We're generating some report data for clients during the offhours, but the clients want the results e-mailed no earlier than 8am.

Our reports often contain images or other attachments that need to be included e-mails. One issue I really don't like about the implementation of CFMAIL in CFMX is that it requires attachments to be written to disk before you can send the mail. This means if I want to use the CFMAIL tag to deliver delayed e-mails, I would to manage attachments until I'm sure the message is delivered. I don't like that solution, so I set out to see if there might be other ways of generating attachments from binary data in memory. This lead me to researching the JavaMail API—which is the API that CFMAIL uses behind the scenes.

I quickly learned that even CFMX v7.02 still uses JavaMail v1.3.1—which is an older version of the API. One of the issues in v1.3.1 is that it does not include any classes for taking a binary stream from memory and converting to an attachment. It comes with a FileDataSource class—which will read in a file and convert it to the correct data source. This might be the reason that Macromedia/Adobe requires the file to be written to disk.

more…


My jQuery Autocomplete Mod

On a recent project I was working on, I needed an "autocomplete" form field that could do both local data array and AJAX lookups. After doing some searching, I came across Dylan Verheul's jQuery Autcomplete plug-in.

This plug-in did a lot of what I needed, but was still missing some of the functionality I required. So, I just modified the library so it worked the way I needed it to. Here's a list of the changes/enhancements I made:

  • Supports local data array (can now use w/out AJAX).
  • Limit dropdown to XX number of results (good for limiting the results to users)
  • Autofill pre-populates text box as you type
  • New findValue() method can be used to programmatically determine if the value in the box is a valid option. (Useful for verifying the text entered is an existing value option.)
  • Dropdown options now correctly re-position themselves on each display (which means they adjust for changing to the DOM)
  • Dropdown box defaults to the width of the input field its attached to (you can manually specify a larger width as well)
  • Better emulates Windows autocomplete boxes (for example: hitting delete and retyping the same box will now bring back the dropdown menu)
  • Miscellaneous bug fixes

more…


Associating Parent/Child Custom Tags (UPDATED!)

UPDATE:
Earlier today I posted a solution to this problem, but after reading a comment by Doug Hughes, I've found a better way to solve this problem, so I'm updating the code. This updated code uses the parent tag as an iterator to loop through the results, which gives Mark the output more to what I think he was after.

Mark Drew posted a question on his blog wondering how you might pass data to a custom tag that acts as a loop. In his post, he's trying to get the following code:

<cfimport prefix="cms" taglib="tags">
<cms:text value="bob">
<cms:loop from="1" to="10">
<cms:text value="bob">
</cms:loop>

more…


Dina Programming Font...

Reading blogs the other day, I came across the Dina Programming Font. I've been testing it out for the past couple of days in Eclipse and so far I really like it.

Over the years I've tried a number of different fonts for my IDE, but I always end up back with Courier New—mainly because it's familiar. However, I've been able to use the Dina font at 8pt and it retains it's readability very well at 1028x768. Lowering the point size while not adding strain for my eyes, allows me to see more code on the page w/less scrolling. Since I have carpal tunnel, anything that reduces mouse movement is a welcome change.


Using Eclipse v3.1 and Subclipse v1.0.3 with newer versions of TortoiseSVN

I recently upgraded a few of my installation of TortoiseSVN to the latest revision. Every since doing this, I've been unable to use Subclipse v1.0.3 (in Eclipse v3.1) to change repositories that have been touched with TortoiseSVN. This is because the newest version of TortoiseSVN using the v1.4 of the client libraries and Subclipse v1.0.3 is based on the old v1.3 client files.

Since one of my development boxes only has Eclipse w/Subclipse, it's been a pain to deal w/this compatibility issue. So, this morning I set out to find a solution to this issue.

Fortunately, I was able to find a post by Mark Phippard that addresses solving this issue (while for Subclipse v1.1.6 anyway.) I did run into an issue that apparently doesn't affect the newer version of Subclipse, but since I'm still using Eclipse v3.1 at the moment, I'm stuck using Subclipse v1.0.3.

more…


CFMX UDF: Parsing a URI into a struct...

Ever needed to parse a qualified URI to examine a URL for specific information? I'm working on some code that needs to examine links in a document and extract information about the links.

To make sure I was doing things by the spec, I made sure to check out RFC2396. Fortunately, the RFC has a nice little regular expression for breaking a URI into it's core pieces: scheme, authority, path, query and fragment.

However, those core portions are still pretty broad. The authority can include user info, domain and port information. The path can include embedded parameters inside each segment. So, I took the core regular expression to break up a URI and then I do further parsing on the authority and path portions of the URI.

more…


Fiddler Issue: Slow running HTTP requests on local IPs (i.e. 192.168.1.*)

For those of you using Fiddler HTTP Debugger (which is a great tool I've blogged about many times in the past,) there appears to be an issue when using IP addresses. This is especially noticable when using private subnet IP addresses (such as 192.168.1.*.)

The problem I was seeing was that requests to my developer server came to a crawl when using Fiddler. Speed to external domains was working fine. If I turned off capturing, speed resumed. I finally was able to figure out that by setting up a DNS entry, speed would resume.

Since this was slowing me down, I sent Eric Law, the developer of Fiddler, an e-mail message reporting the problem. He was very quick in researching the problem.

more…


CF TIP: Determing if a UDF argument is "null"

Ok, so the title is misleading. CF doesn't really have a concept of null, but it does have the concept of "not exists."

If you need to differentiate between when an argument of a function has been supplied or not, set the required attribute to true and leave the default attribute off. If the argument is not supplied to the function, then a against structKeyExists(arguments, "argumentName") will return false. If a value has been supplied, the function will return true.

Here's an example:

more…


CFMX UDF: Creating a query from a zip file

The other day I had the need to unzip the contents of a zip file. However, I did not want to unzip the file to disk, I really wanted to grab the binary data in memory so I could write it to MS SQL as an image data type.

As I normally do, I first did a quick Google and CFLib.org search to see if I could find anything that did exactly what I wanted. The only examples I could find were of writing the zip contents to disk. While I could have written to disk and then read the file from disk, I know I could do what I wanted by just creating a ByteArrayOutputStream. So I took the unzipFile UDF I found (written by Samuel Neff) and basically re-wrote it.

I decided I actually wanted to return a complete query object of all the zip file information. I thought this would be useful for other projects (in case I ever need to "browse" a zip file.)

more…


CFTHREAD/CFJOIN POC released!

Damon Cooper has blog Rupesh Kumar's latest CFTHREAD Proof of Concept (POC).

Rupesh is an Adobe "scientist" (a cool word for CF Developer Engineer.) He was very active in listening to feedback from the original version of the code that was released. I, along with a few other developers, were in active discussions with him over issues with the first release. Thanks to Rupesh's hard work, he's addressed the issues that were discussed.

The biggest changes are the addition of being able to pass attributes to the CFTHREAD tag (which allows you to pass in variables who's values can't change,) threads having their own unique scope (so that variables outside the thread aren't negative affective,) and the addition of the thread.OUTPUT and thread.ERROR variables.

more…


Calculating the visual length of a string

Sorry I haven't blogged in a while, but I've been very busy working on a project. Part of the project requires that I convert HTML to formatted plain text. On the very surface, this may seem simple (just use a RegEx to remove the HTML,) but the key word in that first sentence was "formatted."

One of the many issues I've run into, is that none of the built-in ColdFusion string manipulation functions account for the "visual" length of a string. Since one of the things I needed to do was wrap text after XX number of visual characters; I needed a function that, unlike the standard len() function, would return the length of a string as it would appear on the screen. This means I have to take into account how many "spaces" a tab would occupy on the screen.

My first attempt was simply to count every tab character (chr(9)) as 8 spaces. While this number assured I would never go past the right edge of the content, it wasn't very accurate (as a tab can very between 1 space to 8 spaces in Windows.) I quickly started running into problems when I realized that for some functionality (like centering text,) I'd really need an accurate account of the total number of visual spaces a string was occupying.

more…


Using CF to automatically pass form fields from page to page

I'm working on a project that requires state to be passed via form fields (i.e. a multi-step wizard.) This means that I end up needing to pass hidden form fields from page to page. This normally requires a funky series of if/elses to determine which values to include on each form. Also, as things change from one form to another, you'd need to update each page in the process to include the hidden form field required, otherwise the value gets lost.

Anyway, I started thinking it would be nice if I didn't have to write any if/else statements and just have the necessary fields required automatically passed. Well, if you're thinking "Why not just loop over the form scope?" Well, that's only part of the solution. You really need to exclude fields that are already on the page.

Fortunately, several years ago I had written some code that was part of a much bigger project, that could parse a string and find form fields and extra information about about the fields. Harvesting the code I had already written, I was able to whip out a tag that would parse the content between the start/end tags, look for any form fields in the content and exclude those fields from being copied as hidden form fields.

more…


A ColdFusion UDF For Dynamically Loading Java Classes

UPDATE:
2007-09-21
I just noticed today that the createClass() function below was an old version of the actual code I'm using, so I've updated the code with the latest version.

I've been working on modifying some ColdFusion based web services for XStandard originally written by Ben Nadel. One of the things the original code didn't support was the Spell Checker support feature built-in to XStandard.

After doing some searching, it appeared the Jazzy Spell Checker Java API would fill my needs nicely. It's based on the algorithms in aspell and it can use both dictionary and phonetic files to help with spelling suggestions and it returns all the information required by XStandard (position of word and suggested spellings.) The only "disadvantage" of Jazzy is that it does come "ready-to-use" with CFMX—you need to write a wrapper class for easy use w/ColdFusion. (More on that to come in a later post.)

more…


MSSQL 2k Stored Procedure for Pagination...

A while back I found a stored procedure that someone was using to create pagination resultsets in SQL Server 2000. While the stored procedure was nice, it didn't allow for the "DISTINCT" keyword—which is necessary for some of my queries. There were also a few other issues I didn't like about the stored procedure, so I re-wrote the stored procedure pretty much from scratch.

In order to support the "DISTINCT" keyword, I had to change the inner query to use a derived table. Since this provides a little more overhead, I added a bit parameter "@Distinct" which inserts the "DISTINCT" keyword into the query and uses the derived table.

Also, on the initial page of results, I simply use the TOP keyword. The previous stored proc used an inner query, which did a TOP 0—which means the code did nothing.

more…