Entries for month: “December 2011”

ColdFusion Zeus POTW - Extra edition again...

Posted By: Ray Camden 2 Comments December 22, 2011

Hey, it's the holidays, so why not share one more quick ColdFusion Zeus update? This is another little feature that literally became available two days ago. If you've ever needed to dynamically invoke a CFC method, you know that's simply enough using cfinvoke. So for example:

<cfset s = new some()>
<cfset dynmeth = "test">
<cfinvoke component="#s#" method="#dynmeth#" returnVariable="res">
<cfdump var="#res#">

But of course, that's tag based. How do you do this in script? Unfortunately, the only way to do it was with evaluate, and while evaluate isn't as slow as it used to be, it can get messy to use.

ColdFusion Zeus corrects this by adding an invoke function.


<cfset s = new some()>
<cfset dynmeth = "test">

<cfset res = invoke(s, dynmeth)>
<cfdump var="#res#">

The first argument is either an instance of a CFC or the name of a CFC. The second argument is the method to call. If you need to pass arguments, then you can simply add a third argument - a struct.


<cfset res = invoke(s, "sum", {x:4, y:9})>
<cfoutput>#res#<p /></cfoutput>

By the way - take note of the fix to implicit struct notation. You can still use an equals sign ({x=4}), but colons work now too.

As a final quick aside - a certain person decided to take my words out of context regarding these Zeus previews I've been doing. That person also hasn't bothered to approve the comment I added 24 hours or so ago. I'm not going to bother linking to troll bait, but to be clear - these Zeus previews have intentionally focused on small things. It's easier for me to write, and secondly, it lets me ramp up slowly to the larger things we've announced already, like REST, closures, and web sockets. (Also, some of our larger features are still being hashed out.) For folks who attended my MAX preso, you already know this. Personally I'm really enjoying sharing these small, but useful, improvements, but I want folks to know that - obviously - we have bigger things in the works.

Respond Now

ColdFusion Zeus POTW - Extra edition...

Posted By: Ray Camden No Comments December 21, 2011

Ok, I know I did a Zeus POTW earlier this week, but I had to share this little gem. This is another small thing - a simple function - and something that's been possible via a CFLib UDF for years. That being said - when I saw this show up in the latest Zeus build today, I had to share.

If you've ever needed to format a date and a time, you know that it requires two calls, ala:

<cfoutput>
#dateFormat(now())# #timeFormat(now())#
</cfoutput>

Zeus adds dateTimeFormat to combine this into one call:

<cfoutput>
#dateTimeFormat(now())#<br />
</cfoutput>

For formatting, the mask is slightly different than before. Masks are based on SimpleDateFormat from Java. So for example:

<cfoutput>
#dateTimeFormat(now(), "MMMM d, yyyy h:mm a")#<br />
</cfoutput>

Yeah, ok, not Earth-shattering, but this was one of a few new functions released in the latest Zeus build that were things I've seen requested for years.

 

Respond Now

ColdFusion Zeus POTW: CallStack

Posted By: Ray Camden 2 Comments December 19, 2011

One of the new language additions to ColdFusion Zeus is the ability to get the current callstack. If that sounds Greek to you, it's simply the ability for a function to know who call it, who called that guy, and so on. It sounds confusing, but a few quick examples will help.

In our first example, I've got a call to a UDF that calls another UDF. That UDF runs one of the two new functions introduced in this blog post, callStackGet.

<cfscript>
function top() {
   return child();
}

function child() {
   return callStackGet();
}
</cfscript>

<cfdump var="#top()#">
</cfdump>

callStackGet returns an array of "invokers", or basically, how in the heck did we get here. Looking at the code it's easy enough to tell that child was called by top, and top was called by our cfdump. When displayed, this is what we get.

Notice the array is ordered from most immediate to the final originator of the caller. Also note that the function is labelled where appropriate. How about a slightly more complex example? Consider the code below.

<cfscript>
function grandparent() {
   return parent();
}

function parent() {
   return child();
}

function child() {
   return new some().test();
}
</cfscript>

<cfdump var="#grandparent()#">
</cfdump>

This is similar to our earlier code, but now child is invoking a CFC as well. Here is some.cfc.

component {

   function test() {
      return callStackGet();
   }

}

And the result...

As expected, it picks up on the different file in the CFC.

Another option is callstackDump. callstackDump returns a string based version of the callstack. It supports logging to a file, logging to console, or simply printing to the browser. Here's a modified form of the CFM we last tested with.

<cfscript>
function grandparent() {
   return parent();
}

function parent() {
   callstackDump(expandPath("./callstack.log"));
   callstackDump("browser");
   return child();
}

function child() {
   return new some().test();
}
</cfscript>

<cfdump var="#grandparent()#">
</cfdump>

Notice I've added two calls to callstackDump. Most likely, this is a more real world example as you won't probably ever return a callstack to the user. Here's an example of how it prints to my browser.

And there you have it folks. I'll be posting another Zeus preview before the Christmas break.

Respond Now

Security Hot-fix released for ColdFusion 9.0.1 and earlier

Posted By: Shilpi Khariwal 8 Comments December 13, 2011

An important security hot-fix is released today for ColdFusion 9.0.1 and earlier. Here is the link to the security bulletin. This hot-fix addresses Cross site scripting (XSS) issues for cfform tag and RDS.

Respond Now

Blue Mango Theme Design By Mark Aplet

Super Powered by Mango Blog