justCF

I recently needed to create some ColdFusion code to call into Zillow so I thought it would be worth sharing.

The first thing you will need is an ID from Zillow to give you access to the http services. They use the term web services but they are really http services. You can find out everything you need to know about getting started and the Zillow APIs here: Getting Started with Zillow

Once you have your ID you can enter it into the below code and test it on your site.

I posted a demo here: DEMO

view plain print about
1<h1>Zillow Zestimate</h1>
2<cfparam name="form.address" default="671 Lincoln Ave" >
3<cfparam name="form.city" default="Winnetka">
4<cfparam name="form.state" default="IL">
5<cfparam name="form.Zip" default="60093">
6<cfoutput>
7<form name="zform" method="post" >
8    Address: <input type="text" name="address" value="#form.address#" size="35"/>
9 City: <input type="text" name="city" value="#form.city#" size="20"/>
10 State: <input type="text" name="state" value="#form.state#" size="3"/>
11 Zip: <input type="text" name="Zip" value="#form.Zip#" size="14"/>
12 <input type="submit" name="getzestimate" value="Get Zestimate" />
13</form>
14
15<cfif isdefined("form.getzestimate") >
16    <cfset hz = 'na'>
17    <cfset lz = 'na'>
18    <cfset csz = form.city & '+' & form.state & '+' & form.zip>
19 <cfset zurl = 'http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=ENTER YOUR WSID HERE&address=#urlEncodedFormat(form.address)#&citystatezip=#urlEncodedFormat(csz)#'>
20 <cfhttp method="get" url="#zurl#" result="zsearch">
21 <cfset xmlResult = trim(zsearch.FileContent)>
22 <cfset request.zillow = XmlParse(REReplace( xmlResult, "^[^<]*", "", "all" ) ) />
23 <cfif findnocase('error',request.zillow.searchresults.message.text ) lt 1>
24 <cfset h = trim(request.zillow.searchresults.response.results.result.zestimate.valuationrange.high.xmltext)>
25 <cfset l = trim(request.zillow.searchresults.response.results.result.zestimate.valuationrange.low.xmltext)>
26 <cfif isnumeric(h)>
27 <cfset hz = dollarformat(h)>
28 </cfif>
29 <cfif isnumeric(l)>
30 <cfset lz = dollarformat(l)>
31 </cfif>
32 <h3>Zestimate Range: From #lz# to #hz#</h3> <a href='#request.zillow.searchresults.response.results.result.links.homedetails.xmltext#'
33 target="_new">
<h3>View Property at Zillow.com</h3></a>
34     <hr />
35        All the other Property Details<br />
36        <cfdump var='#request.zillow#'>
37 <cfelse>
38     Zillow could not recognize address
39 </cfif>
40</cfif>
41</cfoutput>

If you want your code to work across multiple domains when using Google Maps you will need to dynamically change your Google Maps key based on request. Google requires you have a unique key for each host that makes calls into Google.

I solved this by placing a few statements in my application.cfc onrequest function.

The code checks the cgi.http_host and then sets the correct key value.

I created the all the keys at http://code.google.com/apis/maps/signup.html

view plain print about
1<cfif findnocase("123.com", cgi.HTTP_HOST) GT 0>
2 <cfset ajaxparams['googlemapkey'] = 'actual key from google'>
3</cfif>
4<cfif findnocase("345.com", cgi.HTTP_HOST) GT 0>
5 <cfset ajaxparams['googlemapkey'] = 'actual key from google'>
6</cfif>
7<cfif findnocase("567.com", cgi.HTTP_HOST) GT 0>
8 <cfset ajaxparams['googlemapkey'] = 'actual key from google'>
9</cfif>
10<cfajaximport params="#ajaxparams#">

If you just have one host you can alternatively set the key inside the administrator.

As MAX unfolded this year you could feel a major shift across all products to developing apps for all screen sizes. This was not the year of the big release but a year to recognize the shift that is occurring to have all new applications consider all devices from browsers, phones, tablets, and TV consoles. I don't think it was just a coincidence we received free devices, in fact it underlines the transition we are all going through as we write applications for all devices.

It kind of feels like 1997 when everyone became aware the internet was going to overtake the majority of application development. You get that same feeling when you look out over the next 2-3 years when you look at convergence of apps across devices and the move into the family room. (In a strange connection, it's hard to believe the same guy who hit the game winner in game 7 in 1997 is the same guy who hit it in 2010.)

To best capture this evolution all you need to do is watch the opening video of MAX as Kevin Lynch walks thru some timeline charts that demonstrate the changes upon us with bandwidth, browser vs devices, screen size changes ,digital publishing and the now the family room.

MAX Opens with Multi-Screen Revolution

Throughout the conference we witnesed how products are adding features to support managing screen sizes. ColdFusion did a sneak peek around supporting multi-screens with setting up a scope which will carry the clients device meta data using the CS5 Device Central database. Dreamweaver is adding more support around using CSS versions to support differing layouts based on device.

One big announcement was the Flash Builder 'Burrito' Labs release which is now available to everyone inside http://labs.adobe.com . I'd encourage you to download and check out how easy it is to start writing Mobile applications.

Here is a great alert to keep on all the time or when you are trying to capture long running requests. The snapshot will then capture the running thread and make it easy to identify where the thread is with processing the request. Usually you can find the exact line number within the ColdFusion tag.

The below code will turn on monitoring and then set UnresponsiveServerAlert to create a snapshot anytime 1 or more requests goes over 5 seconds.

You can change any these settings including seting up notifications. You can set this up via the ColdFusion Administrator, but you might find it easier to setup alerts via script if you have a number of servers.

view plain print about
1<cfapplication name="compinvoker" sessionmanagement="Yes">
2<cfobject component="cfide.adminapi.administrator" name="admin">
3<cfobject component="cfide.adminapi.servermonitoring" name="sm">
4<!--- Login to CFAdmin using your admin password--->
5<cfset admin.login('admin')>
6
7<!---Turn on monitoring--->
8<cfset sm.startMonitoring()>
9
10<!--- For the record let's see the current settings--->
11<cfdump var="#sm.getAlertSettings("unresponsiveserveralert")#">
12
13<cfset alertSettings = StructNew()>
14<cfset alertSettings.alert_processing_cfc = ''>
15<cfset alertSettings.busytimethreshold = 5000>
16<cfset alertSettings.dumpsnapshot = true>
17<cfset alertSettings.enabled = true>
18<cfset alertSettings.hungthreadcount = 1>
19<cfset alertSettings.killthreadsenabled = false>
20<cfset alertSettings.killthreadthreshold = 0>
21<cfset alertSettings.notifyclientonalert = false>
22<cfset alertSettings.notifyonalert = false>
23<cfset alertSettings.rejectrequestsenabled = false>
24
25<!--- Set the unresponsiveserveralert alert --->
26<cfset sm.setAlertSettings("unresponsiveserveralert", alertSettings)>
27
28<!--- Let's verify the new settings--->
29<cfdump var="#sm.getAlertSettings("unresponsiveserveralert")#">

A quick block of code to demonstrate how to generate a stack trace from within ColdFusion. Using the server monitor API it is a fairly simple process.

view plain print about
1<cfapplication name="cfmonitor" sessionmanagement="Yes">
2<cfobject component="cfide.adminapi.administrator" name="admin">
3<cfobject component="cfide.adminapi.servermonitoring" name="sm">
4
5<cfset admin.login('YOURADMINPASSWORD')>
6<cfset filename = sm.dumpSnapShot()>
7<cfoutput>
8Snapshot was placed in: #filename#
9</cfoutput>

The code calls the login function passing in your ColdFusion Admin password in order to get access to the Admin API.

The dumpSnapShot function will create the stack trace and return the file path of the snapshot. The default location is usually ../web-inf/cfusion/logs/snapshots.

You might want to prompt for a password versus hardcoding in the tag as well.

Adobe has recently made available an awesome bundle promotion around ColdFusion 9 Enterprise.

If you plan on buying new or upgrade licenses it might be a good time, you get 3 Free licenses of ColdFusion Builder 1.0 for each ColdFusion 9 Enterprise.

Give us a call if we can help with your order.

I recently had to loop thru a query and break it out into separate sheets inside one spreadsheet. Here is a quick walkthrough on how you can code this with the new ColdFusion 9 spreadsheet functions.

1. You may need to adjust the requesttimeout if you are working with a large number of records.

view plain print about
1<cfsetting showdebugoutput="no" requesttimeout="300">

2. Create your main spreadsheet and all the sheets you need, the below spreadsheet will have 3 sheets 'mainSS' represents the first sheet.

view plain print about
1<cfscript>
2theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "YOURFILENAME.xls";
3mainSS = SpreadsheetNew("mainSS");
4SpreadsheetCreateSheet(mainSS, "mySheet1");
5SpreadsheetCreateSheet(mainSS, "mySheet2");
6
</cfscript>

3. Create your query

view plain print about
1<cfquery name="q1" datasource="YOURDSN">
2 select firstname,lastname from employees
3</cfquery>

4. Set Header Rows - you will need to decide how you want to use header rows by sheet, for this example I am setting one row to make note of it.

view plain print about
1<cfset SpreadsheetAddRow(mainSS,"Firstname,Lastname")>

5. Loop thru query and decide what sheet will receive the data by using the SpreadSheetActiveSheet Function

view plain print about
1<cfloop query="q1" >
2<cfif firstname eq 'Mary' >
3<cfset SpreadsheetSetActiveSheet (mainSS, "mySheet1")>
4</cfif>
5<cfif firstname eq 'John' >
6<cfset SpreadsheetSetActiveSheet (mainSS, "mySheet2")>
7</cfif>

6. Add data row to sheet that was made active

view plain print about
1<cfset SpreadsheetAddRow(mainSS,"#q1.firstname#,#q1.lastname#")>
2</cfloop>

7. Your spreadsheet is now ready to be saved, the below will write the spreadsheet to a file, replacing any existing file

view plain print about
1<cfscript>
2     spreadsheetwrite(mainSS, theFile,'',"yes");
3
</cfscript>

Note: I did need to pass in an empty string for the 3rd parameter, which is a spreadsheet password, otherwise I was getting a compiler error.

At this point you can open your spreadsheet and view your data as you organized it inside the sheets.

I was just reading the the CF Wiki tonight and found that yesterday was CFs birthday.

http://en.wikipedia.org/wiki/ColdFusion

The first version of ColdFusion (then called Cold Fusion) was released on July 10, 1995.

ColdFusion has come along way the last 15 years. (per wiki)

  • 1995 : Allaire Cold Fusion version 1.0
  • 1996 : Allaire Cold Fusion version 1.5
  • 1996 : Allaire Cold Fusion version 2.0
  • 1997-June : Allaire Cold Fusion version 3.0
  • 1998-January : Allaire Cold Fusion version 3.1
  • 1998-November : Allaire ColdFusion version 4.0 (space eliminated between Cold and Fusion to make it ColdFusion)
  • 1999-November : Allaire ColdFusion version 4.5
  • 2001-June : Macromedia ColdFusion version 5.0
  • 2002-May : Macromedia ColdFusion MX version 6.0 (build 6,0,0,48097), Updater 1 (build 6,0,0,52311), Updater 2 (build 6,0,0,55693), Updater 3 (build 6,0,0,58500)
  • 2003-July : Macromedia ColdFusion MX version 6.1 (build 6,1,0,63958), Updater 1 (build 6,1,0,83762)
  • 2005 : Macromedia ColdFusion MX 7 (build 7,0,0,91690), 7.0.1 (build 7,0,1,116466), 7.0.2 (build 7,0,2,142559)
  • 2007-July-30 : Adobe ColdFusion 8 (build 8,0,0,176276)
  • 2009-April-04 : Adobe ColdFusion 8.0.1 (build 8,0,1,195765)
  • 2009-October-05 : Adobe ColdFusion 9 (build 9,0,0,251028)

Happy Birthday Coldfusion!! Here's to many more...

BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.004.