More cfwindow Fun (Model-Glue, too!)

Working on a Model-Glue application, I found myself in a situation where a <cfwindow> would come in handy. It’s on a page that displays a list of items that belong to a user. For each item, the user can add a “journal entry”. This is simply a plain text field and a time/date stamp. Each entry displayed on the page has a link for “journal” that pops up a cfwindow that shows all of that item’s journal entries, along with a form (a simple textarea) allowing the user to add a new entry.

Using <cfform> allows the form submission to stay within the <cfwindow>, which worked great. A standard post allowed the page to refresh after the form was submitted (and the record inserted into the database), so it seemed to be a pretty user-friendly way to allow multiple journal entries to be added to an item. When the user was done adding entries, simply close the cfwindow.

Here’s where things got funked up… the first form submission worked great. The form’s action page called an event-handler that did the insert, and added a named result to the event to redirect back to the journal.viewJournal event, which (obviously) displayed the contents of the journal. The event needed the concept of a transactionID, so i used the append attribute of the result tag as follows:

<result name="success" do="journal.viewJournal" redirect="true" append="transactionID" />

When I went to add a second entry, however, the cfwindow tried to reload into the main/parent window. No matter how many times I tried, the first submission would work (the form submitted to the cfwindow), but the second submission would break (the form submitted to the parent window). realizing I needed the big guns, I whipped out Firebug.

It seemed the original submission (the one that worked consistently) had a few parameters that would appear to have been added by CF:

  • _cf_clientid
  • _cf_containerID
  • _cf_nocache
  • _cf_nodebug
  • _cf_rc

So, I tried adding them to the append attribute of the result tag as follows:

<result name="success" do="journal.viewJournal" redirect="true" append="transactionID,_cf_clientid,_cf_containerID,_cf_nocache, _cf_nodebug,_cf_rc" />

Fixed things right up. I could do submission after submission after submission, and they all worked within the cfwindow. Not being the type of person who believes in overkill, and out of a bit of curiosity, I did try whittling down the list. Seems all I really needed was the _cf_containerID (makes sense, since it was the concept of the container that was being lost). So, the code ultimately turned out to be:

<result name="success" do="journal.viewJournal" redirect="true" append="transactionID,_cf_containerID" />

And with that… I’ll call it an evening.