Friday, May 8, 2015

ColdFusion Oddities

I started working [again] with ColdFusion at work recently. We've also migrated from version 9 to 10. And I'm frustrated a lot from certain 'features' that isn't working as expected. This is probably due to legacy settings when I took over the system. But it's annoying nonetheless and I thought I should document it for future reference. If you know of a better workaround, feel free to leave me a comment.

1. "The specific CFC [name] could not be found."

In an attempt to bind a CFC to a CFGRID, you may have seen its inability to find the said CFC file.
<cfgrid name="books" format="html" bind="cfc:books.getRS({cfgridpage},{...},{...},{...})"...
This is because, most likely, the ColdFusion is looking under installation directory's wwwroot (ie. c:\coldfusion10\cfusion\wwwroot). But why? In the same page, I can instantiate an object as follows:
<cfobject name = "book_object" component="books"/>
Whatever the reason, adding a mapping in my Application.cfc didn't do the trick. Instead, I ended up adding a mapping "/mycfc" in the CF Admin site. As a result, my working code looks like this:
<cfgrid name="books" format="html" bind="cfc:mycfc.books.getRS({cfgridpage},{...},{...},{...})"...

2. "Import for tag CFFORM are missing. Use CFAJAXIMPORT..."

So it may be a violation of some Web Programmer's ethics, but I have a single page, "Index.cfm" that uses CFLAYOUT and in it is how I display all my contents. Hence, no need to put header and footer onto each of my pages.
<cflayout type="vbox" name="mylayout">
  <cflayoutarea>header...</cflayoutarea>
  <cflayoutarea name = "body">
    <cfdiv id="contentHere" bind="url:home.cfm"/>
  </cflayoutarea>
  <cflayoutarea>footer...</cflayoutarea>
</cflayout>
So all the content goes in the highlighted portion. But if I try to put a page with CFFORM or CFGRID, it refuses with a something is missing error. If the same page is requested from outside of the cfdiv, it works without any problem. A way around this problem was to put the following line above the <cfdiv.../> line.
<cfajaximport tags="cfform,cfgrid">

3. A cfinput checkbox cannot be used alone.

So with the previously mentioned cfgrid, I had added a filter checkbox, and I passed this to the bind argument. But it kept seeing the value of the checkbox as "yes", even when it wasn't checked.
Admin Only?: <cfinput type="checkbox" name="adminOnly" value="yes" id="adminOnly" onClick="refreshGrid()">
For clarification, refreshGrid() is a javascript function that calls the ColdFusion.grid.refresh command.
The only way around this that I could tell was to add a second checkbox that had the "no" value and hide it.
<cfinput type="checkbox" name="adminOnly" value="no" disabled="disabled" style="opacity:0">


More to come...

AWS WAF log4j query

How to query AWS WAF log for log4j attacks 1. Setup your Athena table using this instruction https://docs.aws.amazon.com/athena/latest/ug/wa...