ColdFusion Muse

Number Formatting in Coldfusion - a look "Under the Hood"

Formatting numbers is a pain. It would be great if our little human pea brains could read a number without commas in it to group the hundreds (or periods for my European readers). Sadly, we find ourselves unable to cope without the commas, so a good deal of display code regarding numbers is written to simply output them in the correct format. Most CF programmers use numberFormat( ) or decimalFormat( ) to control the output. Decimal format seems handy because it doesn't require a mask and produces the typical format you would expect. The 2 functions are quite different however and it may cause some perplexity when you are working with large numbers. Let me explain.

Note: Examples provided by Russ "Snake" Michaels from the CFGURU list :)

[More]

Cfdocument and Performance

CF Muse Reader Asks:
I am using CFMX7 on Windows 2003. We are seeing some serious processor peaks when the Cfdocument tag takes off to write out a report. We have the latest hot fixes in place...any suggestions?

Cfdocument is a new weapon in the Coldfusion arsenal. It's not without it's detractors, but personally I think it is splendid for what it can do. When it comes to performance, however, there are a number of things to keep in mind. If you think about what Cfdocument is being tasked to do under the hood and I'm sure you could come up with a few as well. Since it is my blog, we might as well work from my list...

[More]

Crashing Your Server in an Infinite Number of Steps

Infinite loops are great fun. Technically an infinite loop is one with no hope of ever stopping. In the old days(1995) I worked for an outfit with a database product for salvage yards. The whole thing was written in MUMPS and everything was done through a terminal. The first program I ever wrote myself was a "spinner" program. It ran on the terminal and produced the following characters 1/2 second apart - "/,|,-,\,|" the result was a little spinning widget on the terminal. I added some text that said "rebuilding dataset, please wait". Whenever we were working on something and needed a way to keep folks from hassling us with new issues we would put it up on the screen. It looked like it was really doing something. With an http request it's a different story however...

[More]

Watch out for Coldfusion Mappings When Using onReqest( )

I love using the application.cfc file instead of application.cfm. The cfc approach encapsulates several events inside of automatically fired functions that formerly required "hand coding". For example, I used to check to see if application vars existed and set them if they did not. This required thinking about locking and testing one or more variables for existence (isDefined() or structKeyExists()). Using Application.cfc means this job is handled by the onApplicationStart( ) function. One function that belongs to Application.cfc deserves a bit more attention - the onRequest( ) function. Here's an example from a webtop application that forces login.

[More]

CFCHART Workaround for labeling horizontal charts

This is a nice tip from Dan Switzer on a fix for a tricky cf chart labeling problem. Sometimes when using an overlapping horizontal bar chart, the labels fail to appear or go missing. In this example from Robi Sen, the first and third labels are there but the middle label is missing.

[More]

Flash Remoting on CFMX7 Multiple Instances

If you use flash remoting on multiple sites on the same server you have probably had to configure the JrunScripts virtual directory. On the standard edition this virtual directory points to the folder <%cfusionmx7%>/runtime/lib/wsconfig/1. When you are running multiple instances you end up with several folders in the wsconfig folder - 1 for each instance (FYI - the root of a multi-instance CF installation is JRUN4, not ColdfusionMX7 as you might think). You might suspect that each site needing flash remoting should point this virtual to "it's own" instance. This is not the case. As Russ (a.k.a. "Snake") pointed out in a recent cfguru post, you must point this virtual to folder number 1. So...

C:\JRun4\lib\wsconfig\2
...would not work, but...
C:\JRun4\lib\wsconfig\1
...does work. I'm betting there is some other setting in a config file somewhere that needs to be adjusted to bring the instances into alignment with flash remoting.

Coldfusion Administrator and the jvm.config file (a love-hate relationship)

If you are using CMFX and trying to "tune" the JVM - or maybe even just adding a class path, I have some advice for you. Don't use the CF Administrator to do it! Instead, get used to editing the jvm.config file located in cfusionmx7/runtime/bin. Not only will you benefit from gaining a better knowledge of the inner workings of your JVM, but you will also miss out on a ticklish bug that will have you scratching your head in frustration. Here's the scoop.

[More]

IsDefined() Vs. StructKeyExists() - The Nuances of CFMX Structures

There's a very interesting post and discussion on Brian Kotek's blog today dealing with the use of the function "isDefined( )" vs "structKeyExists( )". If you've been programming since the days of CF 4.x and "parameterexists()" you'll know that using isDefined() can be a delicate experience at times. It becomes especially tricky in CFMX where the way variables are initiated has changed. In the old days you could have a variable in the variables scope that included a period in the name, and unless you specifically called "structNew()" it would stand as primitive variable in the variables scope. Take this Example:

[More]

Application Name Gotcha - Case Sensitivity

You may have read one of my previous posts regarding the nuances of working with Application Variables. In the first post I took great pains to point out that the application name is the anchor for all the variables in the application and that naming 2 separate applications the same results in them sharing the same scope. Now, thanks to Jim Davis of Depressed Press I have another "gotcha" to add to the conversation.

[More]

Refreshing a webservice in the Cache

Web services are great - but they are not a magic bullet. You have to become familiar will all their little quirks to use them effectively. This is a nice tip I picked up on the email list for BACFUG (I love the retro logo). Sometimes you might have a CFC that you are calling as a webservice like this:

<cfscript>
// service wsdl file
sdl   =   'http:/' & '/mydomain.com/WS/myservice.cfc?wsdl';
// create object
sv = CreateObject('webservice', sdl);
</cfscript>
If you make a change to a method in the CFC (add or change an argument - or a type), and you refresh your page that uses the web service, you may not see the change. That is because the CF Server creates a "stub" (a proxy class) from your WSDL and puts it in the cache. It does not automatically know that the file has changed. You can refresh the cache from the CF administrator, but you may not always have access to it (if you are on a shared server). In fact, the CF Admin method doesn't always work for some reason. Not to worry, Tarik Ahmed (Cflex.net) offers this programmatic solution.
<cfscript>
// service wsdl file
sdl   =   'http:/' & '/mydomain.com/WS/myservice.cfc?wsdl';
// create object
factory = CreateObject('JAVA', "coldfusion.server.ServiceFactory");
// reference to the XmlRpcService
RpcService = factory.XmlRpcService;
// refresh the object in question
RpcService.refreshWebService(sdl);
</cfscript>

Finding all those sneaky log files in Coldfusion

At some point you will have to troubleshoot server problems. Trust me - it will happen. It's no good sticking your head in the sand or your fingers in your ears (or both - tricky, but doable). Your first question will likely be, "Where do I find out information about what is happening on the server." Fortunately there are a great many log files in Coldfusion. Unfortunately they are not easy to find, and they contain different formats of information. There are 3 "groups" of file based logs on a Coldfusion MX installation. These groups are mostly the same for CFMX 7 as they are for CFMX 6 and CFMX 6.1 (a few exceptions). Here's a rundown:

[More]

Using onSessionEnd in Coldfusion 7's new framework

The new Application.cfc file (as of Coldfusion MX 7) is a great "step up" for the framework. In case you are not familar with it, here's a rundown. You replace the venerable old "application.cfm" file in the root of your application with an "application.cfc" file. It works in a similar way, but there are some extra features and some gotchas. Basically there are 8 function calls that are made by 8 different events that are a part of any application. To put it another way, when certain things happen within the application it fires 8 possible events - which in turn call these functions.

[More]

Declining or Advancing... What is Coldfusion's New Direction?

There's lots of hand wringing over what the Adobe merger means to Coldfusion. That's very important to me as well. In a recent spate of messages on the CF Guru list Robi Sen asked the question "Is CF growing or Declining". A number of excellent opinions where offered. Here's a synopsis.

[More]

Using a DSN connection for Connectionless Access

Macromedia added "connectionless" DSN's in CF 5, then took them away again in CFMX. This much lamented feature was useful in certain instances. One of my favorites was for data export. For one of our e-commerce sites suppliers wanted a daily Access file for orders. We created an export process that copied an Access template to a new location (an Access db with the tables needed). Then we created an ODBC connection to it using the "connectionstring" attribute of CFQUERY and ran an insert routine to copy in the orders. The file was then zipped and automatically emailed to the supplier for drop shipment. In the words of Jimmy Neutron's Dad, "Now you gotta admit that's pretty neat!".

In CFMX however the connectionstring attribute is gone. This is because the system no longer interacts directly through ODBC. Instead it uses JDBC as the data access layer. That's a very good thing. We have had great results with speed and reliability through JDBC. It does put a crimp in our data export plan however. Fortunately there's a work-around. It's not perfect, but it works pretty well.

[More]

Cool query function tip using array syntax.

I often pull in a full data set then use query of a query to pull subsets of data from it. The purpose is to minimize the number of hits to the database server (which is usually the cheif bottleneck of any application). This works pretty well, but today I stumbled on a tip that can really save some effort and reduce the sheer number of lines of code. It has to do with using aggregate functions to derive other values from the data. For example, if I have a large query that is being output in a row and I want totals at the bottom I usually run a query like this:

[More]

More Entries




Blog provided and hosted by CF Webtools. Blog Sofware by Ray Camden.