With ColdFusion 8's new cflayout and cflayoutarea tags, you can now create tabbed dialog boxes like you'd find in any desktop application, complete with Save, Cancel, and Apply buttons. Users will instantly be familar with the interface.
All you have to do is to take your existing form inputs (excluding submit buttons, which you want to leave outside of the tabs so they're always showing) and wrap them in <cflayout> and <cflayoutarea> tags, like so:
<style type="text/css">
body {font: 11px verdana, arial, sans-serif; padding: 20px;}
input[type="submit"] {width: 80px;}
#preferences {width: 100%; height: 240px;}
.ytab {padding: 10px;}
</style>
<p><strong>Preferences</strong></p>
<div style="width: 300px; height: 280px;">
<form action="preferences.cfm" method="post">
<cflayout type="tab" name="preferences" tabheight="180">
<cflayoutarea title="General" name="general">
<p>Field 1: <input type="text" name="" size="20" /></p>
<p>Field 2: <input type="text" name="" size="20" /></p>
<p>Field 3: <input type="text" name="" size="20" /></p>
</cflayoutarea>
<cflayoutarea title="Appearance" name="appearance">
<p>Field 4: <input type="text" name="" size="20" /></p>
<p>Field 5: <input type="text" name="" size="20" /></p>
<p>Field 6: <input type="text" name="" size="20" /></p>
</cflayoutarea>
<cflayoutarea title="Security" name="security">
<p>Field 7: <input type="text" name="" size="20" /></p>
<p>Field 8: <input type="text" name="" size="20" /></p>
<p>Field 9: <input type="text" name="" size="20" /></p>
</cflayoutarea>
</cflayout>
<div style="text-align: right;">
<input type="submit" name="save" value="OK" />
<input type="submit" name="cancel" value="Cancel" />
<input type="submit" name="apply" value="Apply" />
</div>
</form>
</div>
Called in a popup window via JavaScript, the following code looks like this:

As for handling the form submission, it's pretty simple. Put this code at the top of your dialog page:
<cfif IsDefined("FORM.save") or IsDefined("FORM.apply")>
<!--- Save the data to persistent storage --->
</cfif>
<cfif IsDefined("FORM.save") or IsDefined("FORM.cancel")>
<!--- Close this popup window --->
<script language="JavaScript">
opener.focus();
self.close();
</script>
</cfif>
If the user clicks on the "Save" button or the "Apply" button, the form data is saved (to persistent storage, such as session variables or a database); also, if the "Cancel" button or the "Save" button is clicked, the popup window containing the dialog box will close and the user will be returned to the main browser window. If the user clicks on the "Apply" button, the dialog box stays around-- but, according to the needs of your application, you may want to either refresh the main browser or perhaps re-select the tab which was selected before the form was submitted so that you retain state for the user (otherwise, because we're refreshing the page in this example, the user will see the first tab become selected). You could also avoid the page refresh by submitting the form with AJAX. I'll leave tab reselection and/or AJAX as an exercise for the reader.
While CF's tab interface looks pretty nice, there are a few difficulties that I've found while trying to style it:
- The name you specify for your
<cflayout>and<cflayoutarea>tags becomes the value of their ID attribute. - You can specify the width and height of your tabbed layout in a
<style>element by the ID, as I've done above. - If you want to specify styles for your tabs, you can apply them to all tabs by styling the
ytabclass, which is the class that CF assigns to the<div>tags that make up the tabs. - You can't change the background color of the tab area even if you specify it, which is an unfortunate but common aspect of many JavaScript UI's. My guess is that the tabs are created with a variant of the Sliding Doors technique, and that you'd have to modify the images used to make up the tabs to modify the background color (e.g., on my system the tab image is located at http://127.0.0.1/CFIDE/scripts/ajax/resources/ext/images/default/tabs/tab-sprite_flex.gif).
There are also several other dialog interfaces that ColdFusion 8 makes available to us which I'll cover in future posts.
So, do you find this useful? Not useful? I'm curious to hear other thoughts.

Comments (11)
June 13, 2007
12:20PM | #
Thanks dude. I was just working on "Scorpiolizing" my open source list app and needed to do the tabs, so this helped. One note, it seems to auto to 100px height, if you just want it to size to the content of the tab use height:auto;
June 13, 2007
12:30PM | #
@Brian-- you're welcome. I just realized that I didn't need to style the height of my tabs. Instead, I should have just used cflayout's tabheight attribute. I've updated the posting to show the correct technique.
August 29, 2007
3:02PM | #
This was a great help, thanks. I am using the following to change the background color of the tabs and it works. However, the tab colors all still stay white. Any thoughts on that? Or how could I incorporate ytab into this scenario, nothing I do with ytab in my styles.css file or anywhere else seems to make any difference (with or without my tabStyle applied.
Thanks very much!
August 30, 2007
12:37PM | #
@Lyle: As I specify in the posting, the backgrounds of the tabs are all implemented with graphics, not with background colors (most are in http://127.0.0.1/CFIDE/scripts/ajax/resources/ext/images/default/tab/).
To change the background colors of the tabs, you could definitely change out those graphics. But if you don't want to change the default graphic files, there's got to be a way to specify them with CSS. Perhaps the Yahoo! Developer Network has the answers (http://developer.yahoo.com/yui/tabview/#cssref)
September 24, 2007
5:21PM | #
Thank you for your site. I have found here much useful information...
January 29, 2008
4:34PM | #
Try modifying the styles:
.x-tabs-strip .on .x-tabs-right {background: ##D6EEFA no-repeat right 0px;}
.x-tabs-strip-wrap{width:100%;background-color: ##D6EEFA;}
They appear in CFIDE\scripts\ajax\resources\ext\css\ext-all.css. You'll also find other tags that control how cflayout tabs look. The key is to change the url's to colors (see above) and add the styles directly in your code before the cflayout tags. This way, you can have different looking tabs in different pages without modifying the original stylesheets in the coldfusion server.
April 30, 2008
12:51PM | #
I was able to change the background color of the tabs using the post by James Mount. However, i was wondering if it is possible to change the color/text on a per tab basis? I have a set of tabs, and each of those tabs may have a set of sub tabs.
I was able to set the background color of the selected tab (both levels) to blue by modifying the style to:
I was also able to set the text color of the sub tabs to red by modifying the style to:
My question is, can i just alter the text/color of a specific subtab? I tried using the same syntax as above, but does this not work since it's at the <cflayoutarea> level? Can you only modify the tabs at the <cflayout> level?
The first sub tab is coded:
However the code below does not work...
Any help is greatly appreciated, thanks!
May 2, 2008
12:42PM | #
@all
For changing the tab text coloring, I was able to surround my 'title' text with a span inside the cflayoutarea tag
HTH, WilliamJanuary 28, 2009
11:45AM | #
The following works for setting background color of a tab in CF 8.01:
See docs:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_j-l_02.html
HTH
Steve
January 28, 2009
3:26PM | #
Sorry for previous post.
The code should have been:
Steve
September 3, 2010
4:38AM | #
I am really enjoying this website but I am having issues with making the RSS feed to work in the new Google Chrome. Can someone give me a hand? Thank you much!