Blog Author: Scott Stroz

Scott Stroz specializes in developing and deploying enterprise-level web applications, as well as integrating new programming features into older applications to help organizations achieve growth by migrating data management to advanced web technology. His experience with web application development technology spans nearly a decade, during which he was named an Adobe Community Expert. Scott excels at completing unusual, complex and challenging tasks, and he embraces new technology and its possible inclusion in current and future projects, earning him the title “Chief Problem Solver.” Scott is recognized as an industry expert through his speaking engagements at conferences and user groups and contributions to a number of technical publications.

Categories
Blog Archives
Blog RSS Feed

RSS FeedSubscribe to our RSS feed or Atom feed.

The Alagad Technical Team Blog

CFWindow Naming Gotcha

Published By: Scott Stroz on Feb 22, 2008 at 11:36 AM
Categories: ColdFusion

I am working on a small application that can be used to demonstrate some of the AJAX capabilities of ColdFusion 8.  It is a simple master/detail application for managing information about users.  The main page uses <cfgrid> to display the list of users.  When you want to edit a user, or create a new one, I use the ColdFusion.navigate() JavaScript method to load a URL into a <cfwindow>.  This page contains the user form.

Whenever I created or edited a user, it would work as expected...the first time.  The next time I would try to edit or create a user and submit the form, I would get an error from ColdFusion stating that one of the form fields was missing.  Huh?  How is that possible sine the form just worked?  Using FireBug I was able to look at the POST of the form submission.  On the instances where I would receive the error, sure enough, the form fields were not getting posted, but, the <cfgrid> was. Now, how did that happen?  Well, the answer to that question is quite simple.

Here is what the code looked like for the <cfgrid>. 

<cfform name="userGridForm" method="post">

<cfgrid name="userGrid" ......... >
        <cfgridcolumn name="USERID" header="ID" display="false" />
        <cfgridcolumn name="FIRSTNAME" header="First Name" width="200" />
        <cfgridcolumn name="LASTNAME" header="Last Name" width="300" />
        <cfgridcolumn name="EMAILADDRESS" header="Email" width="220" />
        <cfgridcolumn name="PHONE" header="Phone" />
    </cfgrid>
</cfform>

 Here is what the code looked like in the user form, which was a seperate file:

<cfform name="userForm">
    <cfinput type="hidden" name="userId"....../>
    ... {more form fields} ...
</cfform>

 Can you see it?  Do you see the problem?  As soon s I saw that the <cfgrid> was posting instead of the user form, it tipped me off.  When the <cfwindow> is open, there are 2 forms named "userForm" on the page, causing the <cfgrid> to be submitted sometimes, and the user form others.  Why it did not error out everytime I tried to save a user is beyond me.  Changing the <cfform> name to "userGridForm" on the mian page cleared up the issue.

Remember, even though you are in a different physical file, naming can cause issues, especially when using them as I did in this litle demo. 

2 responses to “CFWindow Naming Gotcha”

when I saw the title I thought you were talking about the name attribute of the cfwindow tag. I was trying to use a cfwindow but didn't know how to test if a cfwindow with that name already existed so I ended up using ColdFusion.Window.create instead

I need to do something similar to what you are doing here. I am using a flash form, and need to popup a window to enter or update detail information that will update back to the master table.

When I use <cfwindow> it tells me I need to use the cfajaximport tag for cfwindow....which I have done at the top of the calling page...and again at the top of the called page (where the detail information entered/updated).

I'm new to flash/ajax...I have used cf5 for many years. The new techniques are overwhelming me.

Thanks for your help.
Leon

Leave a Reply