Datecompare Coldfusion

In these days, one of my modules based on date/time comparison. To compare date/time is Coldfusion is kinda complicated before I know of Datecompare(). Once I know it, it could easily wipe out all of my problems. Usage

view plain print about
1<cfif Datecompare(date1, date2, "n") GT 0>
2Date1 is greate than Date 2
3</cfif>

Datepart

  • "s" Precise to the second (default)
  • "n" Precise to the minute
  • "h" Precise to the hour
  • "d" Precise to the day
  • "m" Precise to the month
  • "yyyy" Precise to the yea

DotNetToCFType

In this weekend, I have nothing to do in my room and feel lazy to outgoing anywhere. That's why I wanna spend my time to reading coldfusion documents to enhance my skill. Likewise, I'm planning to take cf8 exam coming July or August so I need to know almost cftags as much as I can. Meanwhile, I found one coolest tag called DotNetToCFType in CFML. It can integrate .NET feature with CFML.

view plain print about
1<!---Create a SQL Command Object--->
2<cfobject action="create" name="sqlCommandObject" type=".Net" assembly="#assemblyList#">
3<cfset sqlCommandObject.init("SELECT [ID], [FriendlyName] FROM [Batch]", sqlConnectionObject)>
4<cfset sqlDataReaderObject = sqlCommandObject.ExecuteReader()>
5<cfset dataTable = createObject(".net", "System.Data.DataTable", assemblyList)>
6<!--- populate the datatable --->
7<cfset dataTable.load(sqlDataReaderObject)>
8<!--- convert to cfquery --->
9<cfset myquery=DotNetToCFType(dataTable)>

UDF (User Defined Function)

In these days, I feel like myself to create UDF, user defined function in cfml. Because, it's reusable and flexible to change when needed. When we want to develop Webservices (SOAP), UDF are the most powerful and compatible for every Web Development Language. That's why I decided I'll always create UDF whenever I develop any programs.

customize cfcatch

Customize cfcatch in Coldfusion is kinda incredible. We can define our own customize "error exception". I believe, it's one of the advantages of using Coldfusion Developer. That's why I love Coldfusion. Customize "error exception" is very simple. We need to integrate following three tags cfthrow, cftry and cfcatch. First of all, we need to define custom type with cfthrow like following.

view plain print about
1<!---
2    Useful Information
3    ==================
4    type = [your exception name]
5    errorcode = [your error code]
6    message = [the message you want to display]
7--->

8<cfthrow type="myexp" errorcode="ERROR-007" message="Oh my god..!! I've been caught.">

Here is how to catch your exception If your application hits to this exception, it will be display error message and error code as you defined.

view plain print about
1<cfcatch type="myexp">
2    <cfoutput>
3        #cfcatch.message#
4        #cfcatch.errorcode#
5    </cfoutput>
6</cfcatch>

Here is full simple coding

view plain print about
1<cftry>
2    ....
3    ....
4    ....
5    ....
6    ....
7    ....
8
9    
10    <cfthrow type="myexp" errorcode="ERROR-007" message="Oh my god..!! I have been caught.">
11    <cfcatch type="myexp">
12        <cfoutput>
13            #cfcatch.message#
14            #cfcatch.errorcode#
15        </cfoutput>
16    </cfcatch>
17</cftry>

cfinvoke, cffunction and cfargument

I'm just intermediate level in WebServices such as cfinvoke, cffunction and cfargument The usage of these three tags are to integrate with different language of web application and share information each other. I'm not nice to clarify more of these three tags, then I'll show what I did with these three tags.

view plain print about
1<cfinvoke
2    component="ContactInformation"
3    method="GetContactInformation"
4    returnvariable="QryContactInformation">

5    
6    <cfinvokeargument name="City" value="Bagan">
7    
8</cfinvoke>
9<cfdump var="#QryContactInformation#">

ContactInformation.cfc

view plain print about
1<cfcomponent hint="Get Information of Contact">
2    <cffunction name="GetContactInformation" access="remote" returntype="query">
3        <cfargument name="City" type="string" required="yes">
4        <cfquery name="QryContactInformation" datasource="#application.mydsn#">
5            SELECT U_ID, U_Name, U_Address FROM tbl_Contacts
6        </cfquery>
7        <cfreturn QryContactInformation>
8    </cffunction>
9</cfcomponent>

Webservices

Well, I'm interesting to create webservices (WSDL) in CF in these days. Because, I wanna test how to integrate two different language by webservices. Developing webservices is very simple. Ok, let's go.

helloWorld.cfc

view plain print about
1<cfcomponent>
2<cffunction name="HelloWorldMsg" access="remote" returntype="string" output="no">
3<cfargument name="name" type="string" required="yes">
4<cfreturn "Hello World : " &amp; arguments.name>
5</cffunction>
6</cfcomponent>

caller.cfm

view plain print about
1<cfinvoke webservice="http://helloWorld.cfc?wsdl" method="HelloWorldMsg" returnvariable="msg">
2<cfinvokeargument name="name" value="PPSHEIN"/>
3</cfinvoke>
4<cfoutput>#msg#</cfoutput>

Javascript UDF

Honestly, I'm so far to develop javascript UDF because I feel like myself to develop Coldfusion UDF instead of Javascript. Yesterday, I need to develop javascript UDF for part of my project. It's for return checkbox value whether this checkbox is being checked or not. It's just simple UDF.

view plain print about
1<form name="frmUDF">
2    <input type="checkbox" name="chkMyCheck">
3    <input type="button" name="btnCheck" onclick="beingCheck(document.frmUDF.chkMyCheck)">
4</form>

JS coding

view plain print about
1function beingCheck(obj) {
2     if (obj.checked == true)
3         var returnCheck = 1
4    else
5        var returnCheck = 1
6        return returnCheck
7    }

JSON (JavaScript Object Notation)

JSON, called Javascript Object Notation is being used for integrating computer systems based on XML and WDDX. If using JSON with CFM, you don't need to do much because CFC can output json data.

view plain print about
1<!--- Send an http request to the Yahoo Web Search Service. --->
2<cfhttp url='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&amp;query="ColdFusion Ajax"&amp;output=json'>
3<!--- The result is a JSON-formatted string that represents a structure.
4Convert it to a ColdFusion structure. --->

5<cfset myJSON=DeserializeJSON(#cfhttp.FileContent#)>
6<!--- Display the results. --->
7<cfoutput>
8
9Results of search for "ColdFusion 8"
10
11There were #myJSON.ResultSet.totalResultsAvailable# Entries.
12
13Here are the first #myJSON.ResultSet.totalResultsReturned#.
14
15<cfloop index="i" from="1" to="#myJSON.ResultSet.totalResultsReturned#">
16    <a href="#myJSON.ResultSet.Result[i].URL#">
17        #myJSON.ResultSet.Result[i].Title#
18    </a>
19    #myJSON.ResultSet.Result[i].Summary#
20</cfloop>
21</cfoutput>

Read more here

Listsort Coldfusion

I've just found Listsort function of Coldfusion this evening when I was struggling for my projects. Briefly, one of pages is getting time  from different type of two Queries. I can't merge these two queries with UNION ALL because of different field. That's why I created one parameter and append time value from these two queries but my senior told me to display these times by order ascending. At that time, I was in trouble and can't think so far how to solve it. That's why reading thoroughtly CFML reference. Finally, I got ListSort(). Usage

view plain print about
1<cfset myTime = "11:00, 10:00, 9:30, 15:00, 21:30">
2<cfset SortTime = ListSort(myTime, "numeric", "ASC">
3<cfdump var="#SortTime#">

Sort_type

  • numeric
  • text
  • textnocase

Sort_Order

  • ASC
  • DESC

Facebook Like Plugin for MangoBlog

Today I've created Facebook Like Pluging for MangoBlog. Honestly, it's very simple to install Facebook Like API into your blog without using my plugin. But, using my plugin is easier than by doing yourself. It's just simple plugin and can choose "standard, button_count and box_count" like Facebook API. Oddly, it's my first plugin for mangoBlog. And feel proud of myself of this plugin.

Plugin Name : Facebook Like

Plugin Version : 1.0.0

Owner : Pyae Phyoe Shein

URL : http://www.ppshein.net/assets/content/facebookLike.zip

Top of Page