Monday, September 10, 2007

Illudium PU-36 Code Generator and Matching table and column names...

First, let me say that I love the Illudium PU-36 Code Generator. It has made my life a lot simpler, even when I find myself editing the xslt files to get code more like I want. But I truly cannot imagine life without it since Rob Gonda introduced me to it.

I will readily admit that I may not have the latest version. Once you start editing those xslt files, you kinda want to stick with it. But I ran into this issue today, and it took me a bit to figure it out. Here's the error:

Bean creation exception in com.model.vendorTypeA.vendorTypeAService
Cannot declare local variable vendorTypeA twice.:Local variables cannot
have the same names as parameters or other local variables.:

Line: -1

Obviously a line number of -1 isn't helping. It did tell me, though, that the object can't be created. This error, technically, is thrown by Coldspring, but has nothing to do with it.

The issue here is that I have a table called "vendorTypeA". It has a field called "vendorTypeA". This is bad. Here's the code portion, and it seems obvious, once you've been through this.

<cffunction name="createVendorTypeA" access="public" output="false" returntype="com.model.vendorTypeA.vendorTypeA">
<cfargument name="vendorTypeID_A" type="numeric" required="true" />
<cfargument name="vendorTypeA" type="string" required="false" />
<cfargument name="isActive" type="boolean" required="false" />

<cfset var vendorTypeA = createObject("component","com.model.vendorTypeA.vendorTypeA").init(argumentCollection=arguments) />
<cfreturn vendorTypeA />

Note the two portions in bold, red. I have an argument of "vendorTypeA" and I'm trying to create a local variable of the same name. One is the field, the other is the object, which uses the table name as the object name. The easy solution here is to simply add "_obj" to the last two lines, as in:

<cfset var vendorTypeA_obj= createObject("component","com.model.vendorTypeA.vendorTypeA").init(argumentCollection=arguments) />
<cfreturn vendorTypeA_obj />

Problem solved. Now the object can be created, either "manually" or through Coldspring.

- Will Belden
September 10, 2007


remotesynth said...

FYI, recent versions have allowed you to create the templates using straight CFML. This feature was a pain to build, but many people seem to hate XSLT (I still prefer it personally for these templates).

Glad the generator has saved you time :)

- Brian Rinaldi

Anonymous said...

Thanks! This post just saved me some time tracking down a similar issue.