Ask a Jedi: Using query data in cflayoutarea

This post is more than 2 years old.

Ken asks:

How can you access cfquery data from within a cflayoutarea using the source attribute ?

<cflayout name="tabReferee" type="tab" align="center">
  <cfoutput query="myQ">
   <cflayoutarea name="tab#currentrow#" title="Title" source="frm_referees.cfm" />

Now let's assume there is a record id column in the query ("rid").

How do I access this column from within the frm_referees.cfm page?

As you probably discovered, if you tried to use rid in the frm_referees.cfm page, you get an error. Why? ColdFusion uses Ajax to load the content. That means the section is loaded after the page is delivered to the browser. A whole other reqest is run by using JavaScript to request frm_referees.cfm.

So to pass just an id value, the solution is to pass it in the url:

<cflayoutarea name="tab#currentrow#" title="Title" source="frm_referees.cfm?id=#id#" />

You can pass other values as well, but you want to ensure the URL doesn't get too long for the browser, and you want to be sure to use urlEncodedFormat() for non-numeric values.

If you did have a lot of values, then you may have to run the query again. Not the complete query of course. Just a query to get information for one row. You could modify your initial query than just to get the ID value. That will make your code a bit more efficient.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Steve posted on 8/1/2008 at 5:11 PM

Sometimes Ray you scare me, your timing is spot on. I spent some time yesterday looking for information pertaining to this exact situation. Couldn't believe my eyes today when I checked the site today and here it is. Tomorrow could you blog about ... :-)