Railo tip: using conditional assignments!

I saw this type of code popping up in some Railo source code, but for some reason did not use it before.

In javascript, I was already using it a long time: var a = (b>100) ? 100 : b, but in Railo? Not yet.

Well, that has changed now! It is much simpler then using IIF(), and has great power:

<cfset testValue = 107 />
<cfset nothigherThen100 = testValue gt 100 ? 100 : testValue />

And you can also use it inline:

<cfset testValue = 107 />
<cfoutput>#testValue# is #(testValue gt 100 ? 'greater then' : 'smaller or equal to')# hundred</cfoutput>

Off course, you can nest these statements:

<cfoutput>#testValue# is #(testValue gt 100 ? 'greater then' : (testValue eq 100 ? 'exactly' : 'smaller then'))# hundred</cfoutput>

If you are new to this concept, the syntax is really simple, once you get the hang of it: (also see Wikipedia)

[statement, evaluated to true or false] ? [value if statement is true] : [value if statement is false]

Pretty nifty eeh? [edit] And it works in Adobe Coldfusion 9 too. [/edit]

6 Comments

Using the Coldfusion filemanager standalone as a file interface

Someone asked me today if you could use the Coldfusion filemanager plugin for CKeditor as a standalone application. That's a great idea, I thought. It can replace the regular file upload fields.

You can view a working example here.

14 Comments

CKeditor 3 with FREE coldfusion filemanager, version 2.1

I finally found time to update the coldfusion filemanager for the CKeditor 3. Check the long list of changes underneath! Also read the original blog post for more info on this filemanager.

I released the first versions in February/March 2010, as you can read in this blog post. Since publishing it, I noticed it had some user interface issues. These issues were mostly javascript-related, and were already existent in the original code by the Core Five labs. But nevertheless, they needed to be fixed.

56 Comments

Railo tip: get a query's columnlist case-sensitive

A member of the Railo mailing list asked if he could get the columnlist of a query object case-sensitive. Because #queryObject.columnlist# always returns it uppercase.

One good answer was to look at #getMetaData(queryObject)#, which returns an array with structs with keys isCaseSensitive, name, typeName.
So that's an option, to just loop over that array.

But I knew it must be easier, so I looked in the Railo source code, and found this simple solution:

<cfset caseSensitiveColumnList = queryObject.getColumnlist(false) />
<cfset upperCaseColumnList = queryObject.getColumnlist() />

Pretty cool eeh? Start using Railo today!

NOTE: see the comments underneath; if you typed the actual column names in the SELECT statement, like in "SELECT userID, userName from users", then the case you used there will be returned. But if you used "SELECT * from users", then the actual table column names are returned.

7 Comments

Railo tip: use a custom function for the cfdirectory "filter" attribute

While searching for something else which had to do with cfdirectory, I saw a lot of questions about the filter attribute of cfdirectory. With this attribute, you can filter the results by extensions or part of the file/directory name. For example "*.gif".

The first question that a lot of people have, is whether they can use multiple file filters. The answer is: Yes. You just need to delimit the file filters by a pipe character, like this: "*.gif|*.jpg|*.png".

Another question was whether you could disallow some files or directories from the listing. Now that's much more complicated, or at least you need to write some extra lines of code to remove these from the original directory listing...

Except on Railo! Because with Railo, you can use a custom function as the filter argument, like this:

<cfdirectory action="list" directory="/test/" recurse="true" name="qFiles" filter="#theFilter#" />
<cfdump var="#qFiles#" />

<cffunction name="theFilter" returntype="boolean">
<cfargument name="fullpath" type="string" />
<!--- disallow a certain directory --->
<cfif refindNoCase("[/\\]DisallowedDirectory[/\\]", arguments.fullPath)>
<cfreturn false />
<!--- allow certain extensions --->
<cfelseif refindNoCase("\.(swf|jpe?g|gif|png)$", arguments.fullPath)>
<cfreturn true />
<cfelse>
<cfreturn false />
</cfif>
</cffunction>

As you can see, the function returns a boolean value "true" or "false". True means that the file or directory will be included into the listing, and when False, it will not.

Pretty cool eeh! Start using Railo today ;-)

By the way, when you test this code on ACF 8 or 9, it does not throw an error, but instead just returns zero records.

5 Comments