Ask a Jedi: Using query data in cflayoutarea

Ken asks:

How can you access cfquery data from within a cflayoutarea using the source attribute ? Eg.
<cflayout name="tabReferee" type="tab" align="center">
  <cfoutput query="myQ">
   <cflayoutarea name="tab#currentrow#" title="Title" source="frm_referees.cfm" />
  </cfoutput>
</cflayout>
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 developer advocate. He focuses on JavaScript, serverless 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 https://www.raymondcamden.com

Comments