Use $ to Instantiate Java Nested Static Classes in ColdFusion

Ok, so this isn't news; apparently its common knowledge to some that you can instantiate a nested Java class by using a $ instead of a . in the name:

<cfset local.RoundRectangle2D = CreateObject("java", "java.awt.geom.RoundRectangle2D$Float") />

I'm posting this because I found it impossible to locate this information on the web. I even had an Adobe tech tell me he was logging a bug that CF couldn't handle nested classes, because even he didn't seem to know that you could do this. Its now in the CF8 LiveDocs, and its now on my website. Perhaps the next person in line will be able to find it easier.

 

Transparent Rounded Corners for the Masses

Ok, so a late night of coding here… I should have been in bed like 2+ hours ago, but its all worth it because I've got it working: fully transparent rounded corners on your images. Just hit "more" to see the code.

 

ColdFusion Intermittently Cannot Find CFC, Part II

Ok, follow up to yesterday's post "ColdFusion Intermittently Cannot Find CFC". I've updated my tests and still no answers. Help me figure out why ColdFusion sometimes doesn't want to CreateObject().

 

ColdFusion Intermittently Cannot Find CFC

Ok, so a new one on me... ColdFusion has started to intermittently fail to find a CFC when trying to instantiate it. I started getting emails that the system was erroring out because it failed to find a component for part of a process in our system, but when I went back to try it myself, things worked fine. I dismissed it as odd until it started to happen more often. Click "more" to see how I replicated the problem and help me figure out what is going on.

 

Utility Functions: ListIsValid() and ListRemoveInvalid()

A gear One technique I often use is to create gateway objects to my database that allow the user to pass in multiple IDs, rather then a single one. I've run into a problem though; what if the user passes through something that is a valid list, but is not a valid list of the type I need? Read more to see ListIsValid() abd ListRemoveInvalid().

 

Utility Functions: CreateMapping() and RemoveMapping()

Some more "stolen" code for today's pair of utility functions. Thanks to FusionGrokker's post on controlling mappings in CF7. As FusionGrokker points out, these functions work in CF7, but its actually hacking global mapping values, so you could have problems.

<cffunction name="CreateMapping" output="false" returntype="void">
    <cfargument name="mapping" type="string" required="true" />
    <cfargument name="path" type="string" required="true" />
    
    <cfset var factory = CreateObject("java", "coldfusion.server.ServiceFactory") />
    <cfset var mappings = factory.runtimeService.getMappings() />
    
    <cfset mappings[arguments.mapping] = arguments.path />
    
    <cfreturn />
</cffunction>

<cffunction name="RemoveMapping" output="false" returntype="void">
    <cfargument name="mapping" type="string" required="true" />
    
    <cfset var factory = CreateObject("java", "coldfusion.server.ServiceFactory") />
    <cfset var mappings = factory.runtimeService.getMappings() />
    
    <cfset StructDelete(mappings, arguments.mapping) />
    
    <cfreturn />
</cffunction>

 

More Entries

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.