Search This Blog

Monday, June 3, 2013

ColdFusion: Logging Errors Using BugLogHQ

I came across a bug/error logger called BugLogHQ. It includes a control panel where user can browse the logs. Setting it up is pretty easy. Follow its documentation page on http://www.bugloghq.com/docs.cfm.

A couple tips. This /bugLog/config/buglog-config.xml.cfm where you define the data source name (DSN), database type, username, and password. For security purpose, Personally, I would not recommend that you set username and password on this config file. If you chose to ignore the username and password, you would need to remove username and password attributes in /components/lib/dao/dbDataProvider.cfc. Otherwise, you would get an error. Another issue that I had during installation where I have MS-SQL Server 2008 installed using Windows authentication, this blog is certainly helpful.

Besides BugLogHQ, there are two other ColdFusion-based loggers I found. They are:

Friday, May 31, 2013

ColdFusion: Working with JSON

JSON has been gaining popularity to represent data in JavaScript applications. Below is an example of JSON data with some array and a ColdFusion parse function to convert JSON data to ColdFusion structure.

<cfsavecontent variable="personnel_record">
{
 "firstname": "John",
 "lastname": "Smith",
 "age": 36,
 "address": {
  "number": "12345",
  "street": "Any Street",
  "city": "Any City",
  "state": "AA",
  "zip": "90876"
 },
 "children": [
  {
   "firstname": "Ian",
   "age": 7,
   "married": false
  },
  {
   "firstname": "Heather",
   "age": 6,
   "married": false
  }
 ]
}
</cfsavecontent>

<cfdump var="#deserializeJSON(personnel_record)#" />

Wednesday, May 29, 2013

ColdFusion: Reduce/Suppress Whitespaces

Without implementing proper technique, by default ColdFusion generates unnecessary whitespaces on result page. This will cause the page size bigger and consequently it will take more time to load the page. To suppress the whitespaces, we can enable whitespace management in CF Admin and/or do one of the following techniques:

<cfsilent>...</cfsilent>
 Absolutely no output. Not even <cfoutput> nor <cfdump>.
 Require closing tag </cfsilent>.
 
output="false"
 One of the attributes in <cfcomponent> and <cffunction>.
 It works like <cfsilent>.
 
<cfsetting enablecfoutputonly="true">
 Only output things that are wrapped with <cfoutput>. 
 It works with <cfdump>.
 The effect goes to <cfinclude> as well.
 Matching tag, <cfsetting enablecfoutputonly="false"> is highly recommended.
 Closing tag </cfsetting> is optional and does not have any effect.
 Multiple declarations behave like a counter. 

<cfprocessingdirective suppresswhitespace="true">...</cfprocessingdirective >
 It reduces whitespaces, but it is not as effective as <cfsilent> or <cfsetting>.
 <cfoutput> is not required.
 Require closing tag </cfprocessingdirective>.

<!--- BONUS --->
<cfsetting showdebugoutput="false">
 Disable debugging mode when Debugging Settings in CF Admin is enabled.

SEE ALSO:
ColdFusion Whitespace Options

Thursday, January 3, 2013

Service-Oriented Architecture (SOA)

I recently found a well-written article about Service-Oriented Architecture (SOA) from Microsoft. Although it is not directly related to ColdFusion, the article gives a nice guidance on how to architect applications to deal with service-based collaboration. 

Here's the link: http://msdn.microsoft.com/en-us/library/ff648490.aspx

Friday, September 21, 2012

ColdFusion: Taking Advantage of Java Classes

ColdFusion is built on top of Java; and it has plumbing to access Java classes. This is pretty cool. That means we can extend ColdFusion's capability.

Here is an example on how to utilize Java's Stack class. What we need to do is to create an object from Java class in question. Here, we created a Stack. As you can see, we can immediately call and utilize its methods.

<cfset objStack = CreateObject("java","java.util.Stack").init() />
<cfdump var="#objStack#" />

<cfdump var="#objStack.empty()#" />
<cfset objStack.push("a") />
<cfset objStack.push("b") />
<cfset objStack.push("c") />
<cfdump var="#objStack.empty()#" />

<cfdump var="#objStack.peek()#" />

<!--- The top element is always one --->
<cfdump var="#objStack.search('c')#" />

NOTE: Often, when we work with electronic payments, the third-party may require us to use certain algorithm for encryption. In this case, Java has more options to choose from than the ones already built in ColdFusion. So, take advantage of Java classes.

Reference:

Monday, September 10, 2012

ColdFusion: Scale Attribute in <cfprocparam>

Want to insert a numerical value that contains decimal using <cfprocparam>, but the decimal portion is not showed up in the database? Most likely, we forgot to specify scale attribute. scale attribute is used to specify number of decimal places. If not specified, the default value is 0.

<cfstoredproc procedure="spuInsertBoxLength" datasource="#myDataSource#">
    <cfprocparam cfsqltype="CF_SQL_FLOAT" scale="2" value="123.45" />
</cfstoredproc>
Reference:

Thursday, August 23, 2012

ColdFusion: Converting Records From Excel to Query

Have you ever needed to get data from Excel to ColdFusion to be manipulated? Before ColdFusion 9, reading records from Excel was cumbersome. <cfspreadsheet> makes the task handy. You can convert the records to spreadsheet object, query, CSV, or even HTML.

Here is an example on how to read an Excel spreadsheet and convert its rows to ColdFusion query.

<cfspreadsheet  
    action = "read" 
    src = "spreadsheet.xls" 
    sheet = "1"
    excludeHeaderRow = "true" 
    headerrow = "1" 
    query = "queryName"
    rows = "2-10" />
 
<cfdump var="#queryName#" />

Attribute rows is useful during development. Instead of reading all records in once, you can just output several records for testing/debugging. For more information on other attributes, please see the reference below.

Reference: