Category Archives: ColdFusion

Blank Page When Introspecting CFC through CFCExplorer

I am working on publishing a web service that will interface our EHR with an external lab provider.  After setting up much of the routines and code, I wanted to introspect the CFC’s I had created to see how they looked.  While there are several tools available to do this, I decided to use the built-in CFC Explorer provided with ColdFusion.  I navigated to my CFC in the browser, but all I got back was a blank page. Nothing else, wasn’t even asked for the RDS password.  I tried this on several other CFC’s with the same result.  I figured there may be an issue with the CFC Explorer itself, so I navigated directly to it by visiting http://localhost/CFIDE/componentutils/cfcexplorer.cfc.  When I did I got the RDS password prompt.  I entered the password and the explorer details presented.  I went back to my original CFC and refreshed, and all of the introspected documentation became visible.  Restarting my system probably would have fixed this also (I know, always restart), but it’s good to know that this method worked as well. 

So if you find yourself with a blank page when visiting your CFC, try hitting up the explorer first.

Publishing Web Services with ColdFusion

My last blog dealt with consuming web services with ColdFusion.  In this entry I will discuss how to publish a web service using ColdFusion.  To reiterate, my knowledge going into this subject was limited, but once again ColdFusion has made a complex topic quite easy to grasp.  In fact, I had actually been using the web service publishing capabilites of ColdFusion for a little while without even realizing it.  Let me show you just how easy it is. 
 
To create / publish a web service, you must start by defining a component, and like any component it may have one or more functions.  Let’s look at this simple Hello World example:
 
     <cfcomponent>
 
          <cffunction name="init" returntype="string">
               <cfreturn "Hello World">
          </cffunction>    
 
     </cfcomponent>
 
So we have a simple component that defines one function name init that returns the string "Hello World".  To turn this into a web service, consumable by any language that supports it, is add ONE attribute to the function:
 
     <cfcomponent>
 
          <cffunction name="init" returntype="string" access="remote">
               <cfreturn "Hello World">
          </cffunction>    
 
     </cfcomponent>
 
All I have done here is added the access attribute to the function and specified its value as remote.  That’s it!  We now have a fully function web service with a method that will return a string.  Assuming this component is named myFirstWebService and it lives directly on your web root, you can call it directly like the following:
 
 
Doing so will produce an html output page featuring descriptions of the web service and its functions from the self documenting features of ColdFusion components.
Add ?WSDL to the end of the URL and you will see the WSDL definition of the service, which is the URL that can be used to consume your brand new service.  And that is it!
 
I hope this brief introduction can help you get started in publishing your own services.  Next time I will discuss object creation in ColdFusion and how to use Objects in Web Services, as well as modeling complex types with structs in ColdFusion.
 
Happy Coding!
 

Consuming Web Services with ColdFusion

The agency I work for is implementing the Avatar clinical software system from Netsmart Technologies.  Netsmart has recently released a collection of Web Services for the Avatar system to extend it’s functionality.   It became my duty to fully leverage these Web Services using my favorite language, ColdFusion.  Up until this point I have never worked with a Web Service or even fully understood what one is.  So, I put on my learnin’ hat and started searching around the web for some information.  I soon learned that a web service, loosely and briefly designed can be summized as a way for two software systems, written in different languages and running on different platforms, to talk to each other using a standardized language they can both understand over a protocol they can both understand.  The language in this case is XML (extensible markup language) and the protocol is HTTP (hypertext transfer protocol).  Okay, so now that I know what it is, how can I use it?  A little bit more research and I found out that ColdFusion makes using a Web Service, which is formally referred to as "Consuming" the service, extremely simple.  In fact, ColdFusion has two equally simple ways to consume: using the <cfinvoke> tag or the createObject() function with the "webservice" argument. 
 
The tag based solution works like the following:
 
   <cfinovke webservice="urlToTheWSDL" method="nameOfMethod>
        <cfinvokeargument name="argumentName" type="argumentType">
                                                .
                                                .
                                                .
    </cfinvoke>
 
For the webservice attribute, all you need to do is specify the URL to the WSDL file of the web service.  Every web service you will consume has an accompanying WSDL (Web Service Defintion Language) file that describes what the web service does, what its methods / functions are , and what data types it takes in and returns.  To call a specfic function of the web service, just supply its name in the method attribute.  If the method takes in arguments, you can specify those using <cfinvokeargument> tags, supplying the name of the argument as well as the type.  The type can be simple (string, numeric, boolean,…) or complex (struct, array, user defined object, array of object, …).  If the web service returns a value, you can use the returnvariable attribute of the <cfinvoke> tag to capture it for further processing. 
 
The function based solution looks like this:
 
     <cfset ws = createObject("webservice", "urlToTheWSDL")>
     <cfset returnValue =  ws.nameOfMethod(arg1Name = arg1Value, arg2Name = arg2Value, …)>
 
  or using scripting…
 
     <cfscript>
          ws = createObject("webservice", "urlToTheWSDL");
          returnValue = ws.nameOfMethod(arg1Name = arg1Value, arg2Name = arg2Value, …);
     </cfscript>
         
All you do here is create a web service object, then call methods of the object passing name / value pairs to it.  While this second method requires two seprate steps to consume the service, I prefer it as I believe it has a cleaner appearance when there are multiple arguments to send to the method. 
 
As I hope you can see, ColdFusion makes working with the basic functionality of Web Services quite painless.  In later posts, I will examine how to create, or publish, a Web Service using ColdFusion, as well as dealing with complex data types that are often used in Web Services.
 
Hope this information is useful.  Happy Coding!

Controlling tab focus ordering in Coldfusion Flash Forms

This is about a simple need with a simple answer.  I am working on  a ColdFusion Flash form and needed to change the order in which fields received focus when using the tab key to navigate.  I checked the ColdFusion documentation and there was no mention of any attribute to control this.  I remembered taking care of this in the past with an HTML form but I could not remember the name of the attribute.  I did a quick google for "tab order input" and came up with the attribute tabindex, which takes a numerical value equal to the order in which a control should receive focus.  Even though it was not in the official ColdFusion documentation, I decided to give it a try on my cfinput and it worked perfectly.  So if you ever need to control the order on which a form control receives focus when tabbing, remember to use the tabindex property.
 
Happy Coding and Tabbing!
 

Resending undelivered email in ColdFusion

We got a new exchange server configured and brought online yesterday.  As a result, I had several emails from various ColdFusion apps and scheduled tasks that were unable to be sent.  When a message is unable to be sent, ColdFusion will move it into the Mail\Undelivr directory under your main ColdFusion installation directory.  After some searching, I came across this little snippet on how to resend those messages.  Turns out it’s really easy. All you need to is copy the unsent mail, stored as a .cfmail file back into the Spool folder in the Mail directory.  Depending on your spool settings, ColdFusion will eventually attempt to resend these messages.  With this knowledge, it would be a great idea to set a scheduled task to periodically go through the Undelivr directory and try to resend the mail.  I’ll post back if I decide to get that working. 
 
Hope this helps.  Happy Mailing!

Making a single cfselect required

I’ve experienced the same frustration as others when it came to requring a value for a cfselect.  The documentation states that you just have to set the required attribute of the cfselect to true and it should validate.  This unfortunately only works for cfselects that allow multiple values (size >= 2).  For a single cfselect, a value is always selected and the requirement will never be properly triggered.  I’ve tried numerous workarounds that always failed to produce the appropriate results.  I finally came across the solutions today, posted from a user on the Adobe Coldfusion MX7 LiveDocs for cfselect.  The solution was so ridiculously simple that I couldn’t help but laugh at myself.  The user pointed out to use the following javascript:

 

<script language="JavaScript"><!–

document.formName.selectName.selectedIndex=-1;

//–>

</script>

Place this script after your cfselect with the required attribute set to true, and it will validate upon form submission.  I have tested this on HTML forms only.  I’ll test later on Flash forms and post my results.

Hope this helps.  Happy Coding!