A couple weeks ago I wrote a post on Enhancing CFWindow with JavaScript, and it was recently asked if there was a way to identify all the windows and their visible status that currently exist on a page where you are using the ColdFusion.Window.create function to create new CFWindow instances. It took a few minutes of digging with FireBug, but I found that there is a ColdFusion.objectCache object that holds information about the various ext object that get created with the ColdFusion AJAX features. I created a function that loops through the objectCache and finds objects that have a "cfwindowname" property. Then used the Ext.BasicDialog.isVisible() function to determine if the window is currently visible.

You can see this working sample here. First press the "Show CFWindow Names" button and it will show you that Window 1 and 2 are visible. Then press the "Create Window3" button and click the "Show CFWindow Names" again and you will see that there are now three visible windows, if you close window 1 or 2 and click "Show CFWindow Names" button it will tell which windows are now hidden.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
<head>
   <title>CFWindow</title>
   <script language="JavaScript">
      showWindowNames = function(){
         for(sProperty in ColdFusion.objectCache)
            {
               if(ColdFusion.objectCache[sProperty].cfwindowname != 'undefined'){
                  thisWindow = ColdFusion.Window.getWindowObject(sProperty);
                  if(thisWindow.isVisible()){
                     alert("There is a visible cfwindow named " + sProperty);
                  }
                  else{
                     alert("There is a hidden cfwindow named " + sProperty);
                  }
               }
            }         
      }
   </script>   
</head>
<body>

<cfwindow
name="MyWindow"
center="true"
closable="true"
draggable="true"
height="500"
initShow="true"
minHeight="100"
minWidth="200"
modal="false"
refreshOnShow = "false"
resizable="true"
title="My Test Window"
width="400">

window contents
</cfwindow>
<cfwindow
name="MyWindow2"
center="true"
closable="true"
draggable="true"
height="400"
initShow="true"
minHeight="100"
minWidth="200"
modal="false"
refreshOnShow = "false"
resizable="true"
title="My Test Window2"
width="400">

window contents
</cfwindow>
<form name="MyForm">
<input type="button" value="Show CFWindow Names" onclick="showWindowNames();">
<input type="button" name="createWindow" value="Create Window3"
onClick="ColdFusion.Window.create('MyWindow3', 'My Test Window3','',{x:100,y:100,height:300,width:400,modal:false,closable:false,draggable:true,resizable:true,center:true,initshow:true,minheight:200,minwidth:200})">

</form>
</body>
</html>

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Dustin's Gravatar Since it's not really documented do you think ObjectCache is safe to use? In otherwords could it be changed going forward in future CF versions?
# Posted By Dustin | 12/20/07 4:47 PM
Scott Bennett's Gravatar As with all undocumented features, there is no guarantee that it will be the same in future versions. So if you do use it, you will have to be sure to check that it still works when you upgrade to CF 9 someday and adjust it if necessary. If it doesn't work in some future release, then I am sure I can figure out another way to make it work, and I'll cross that bridge when it comes. I also think it is very likely that in future releases Adobe will add more AJAX JavaScript functions that are built into ColdFusion, and it won't be necessary for us to come up with these kind of workarounds.
# Posted By Scott Bennett | 12/20/07 5:29 PM
Dustin's Gravatar Thanks Scott.
# Posted By Dustin | 12/20/07 5:30 PM