Here we are again with another ColdFusion lesson learned. The thought that came to my mind when i was working with a CFLayout tab, was how do i refresh the tab’s contents other then using the standard ways of submitting a form.

In this case i had a button that would make an Ajax call to process a selection Asynchronously. After that call i was looking to see how we can display those changes on the tab using Javascript. Well lucky us, ColdFusion Layout objects are accessible using JavaScript. Here is an example:

   <script type="text/javascript">
      ColdFusion.Layout.hideTab('mainLayout', 'userPerm');
      ColdFusion.Layout.showTab('mainLayout', 'userPerm');
      ColdFusion.Layout.selectTab('mainLayout', 'userPerm');
  </script>

What we are doing here is pretty self explanatory. We are hiding the tab first which basicly, removes the tab from the layout. Then we show the tab in the layout which does a call to refresh the contents of the tab. This is the same as doing an Ajax call to get contents of a page except we are using ColdFusion to do it. Then we select the tab in the last step which brings us back to where we started.

Now i will warn you that my experience with this method is flaky at best. The method i found to work without doing a form submission or doing a new pageload, was to do the Ajax call myself instead of relying on ColdFusion.

Now i know it is not easy to run JavaScript that is part of a tab contents, but if you know what calls are needed then you can have your JavaScript functions included on the parent page, which gives you the ability to call those functions within the tabs. What this does is allow you to wrap your tab HTML in a div, then call Ajax to retrieve the contents again, and set the innerHTML of the div equal to the new content. All this done without a whole pageload. Now i am certain there are many ways to skin this cat, but you will see i am a fan of Ajax. I like the experience of processing data in the background which provides clean HTML reloads. If anyone would like to add to this, or critique the method, by all means let me know. I am always open to learning something new!.

Advertisements