Interesting bug with Application.cfc and mappings and the Application constructor
Tags: ColdFusion 8, ColdFusion 9, Coldbox
A few years ago I wrote a small component for ColdBox that actually allowed me to modify the Application settings, specifically the ORM settings and cfclocation. There was nothing special to this component and I had it working for sometime, that was until I moved ColdBox away from the root of the application and used per application mappings instead.
Which is when I discovered something very interesting with Application.cfc and the constructor.
It appears that whether you use per application mappings, or set the mapping via the administrator, the problem is the same. So to illustrate the problem I have given some examples on what works and what doesn't work.
First lets look at what did work before I made the changes to per application mappings.
import test.*;
this.something = new testCom().getSomething();
public boolean function onApplicationStart() output=false {
}
}
Now in the example above the folder test is in the web root, and works fine. But the following will not work at all.
this.mappings['/test'] = getDirectoryFromPath(getCurrentTemplatePath()) & '..\test';
import test.*;
this.something = new testCom().getSomething();
public boolean function onApplicationStart() output=false {
}
}
It should be noted that there is nothing wrong with the import at all, but the application will fail on the line where it is trying to create the component. So to test this theory out I removed the import and made the new with the full path to the component, and still did not want to work.
Now while trying to figure this out I also came across another interesting bug as well, and I could not understand this either. but lets say we do this in index.cfm
obj = new test('something');
</cfscript>
And test was
public void function init(required string value) {
writeDump(arguments);
}
}
You would expect to see that the arguments would have a key called value, and it would have the value something inside of it. Well what if we did this inside application.cfc?
this.something = new test('something');
public boolean function onApplicationStart() output=false {
}
}
We would get an error message that would say that
The VALUE parameter to the INIT function is required but was not passed in.
Even if we placed this into the onApplication start, we get the same error as well.
I find this all a serious problem, because all I wanted to do was modify the cfclocation to reduce the amount of work a developer would need to maintain the cfclocations for Coldbox modules. Which works, but only if ColdBox was not setup using mappings.
-
Scratch the bug with the new test('something'); I found out that I had goofed here, with my test case :-(
# Posted By Andrew Scott | 1/30/12 12:21 PM



TweetBacks