Dumping the service but getting a dump of the handler

I have a service that inherits from the CB VirtualEntityService. I’m calling it from a handler to get the results for a search page. In my service search function I did a dump of “this” and it dumped the handler. I don’t know how or why. It should dump the service. I did a dump because I tried to call the “get” method inside my search method (in my service) and I got an error saying the method couldn’t be found. This makes no sense at all. Any ideas?

And BTW, I’m using version 3.1 but have tried the dev branch from GitHub too.

Upon further investigation, all my services are having the same problem: when executing a method, calling any second method inside my service fails. So it goes like this:

Service.method1() -> method1 executes method2 (which is in the same service) -> error, undefined method

It is as if “this” inside the service is pointing elsewhere. In my case, to the handler that calls the service. Very strange. Any help would be really appreciated. I’m totally stumped.

Dustin,

We will need some code and stacktraces to better help you.

Aaron Greenlee

I am guessing your service is extending the handler in some way.

Here is my service. I have simple method called “test” that I’ve been trying to call. I’ve marked where the method is and where it is called. When I call it I get the error. Further down is the stacktrace.

public DistributionService function init(){

// init super class
super.init(entityName=“Distribution”);

// Use Query Caching
setUseQueryCaching( false );
// Query Cache Region
setQueryCacheRegion( ‘ORMService.defaultCache’ );
// EventHandling
setEventHandling( true );

return this;
}

----> public any function test(){ }

...

<cfreturn query[1]/>

--------------> test();

var query = “”;
var options = {
offset = arguments.offset,
maxResults = arguments.max,
timeout = arguments.timeout
};

...

Oops! Exception Encountered### Application Execution ExceptionError Type: Expression : [N/A]

Error Messages: Variable TEST is undefined.

Tag Context:
ID: ??
LINE: 97
Template: C:\WebRoot\Development\CF\Projects\Backhauls\model\domain\services\DistributionService.cfc
ID: CF_UDFMETHOD
LINE: 43
Template: C:\WebRoot\Development\CF\Projects\Backhauls\includes\helpers\ApplicationHelper.cfm
ID: CF_UDFMETHOD
LINE: 86
Template: C:\WebRoot\Development\CF\Projects\Backhauls\handlers\Distribution.cfc
ID: CFINVOKE
LINE: 699
Template: C:\WebRoot\Development\CF\Projects\Backhauls\frameworks\coldbox\3.1.dev\system\web\Controller.cfc
ID: CF_UDFMETHOD
LINE: 584
Template: C:\WebRoot\Development\CF\Projects\Backhauls\frameworks\coldbox\3.1.dev\system\web\Controller.cfc
ID: CF_TEMPLATEPROXY
LINE: 243
Template: C:\WebRoot\Development\CF\Projects\Backhauls\frameworks\coldbox\3.1.dev\system\Coldbox.cfc
ID: CF_TEMPLATEPROXY
LINE: 103
Template: C:\WebRoot\Development\CF\Projects\Backhauls\Application.cfc
Framework Snapshot
Current Event: Distribution.search
Current Layout: N/A
Current View: N/A
Bug Date: 07/22/2011 02:18:48 PM
Coldfusion ID: CFID=27702 ; CFToken=61e475f39a34a5da-02B77747-2268-1D08-2E79C8033F9C2E0C ; JSessionID=PROJECT_27702_61e475f39a34a5da-02B77747-2268-1D08-2E79C8033F9C2E0C
Template Path : C:\WebRoot\Development\CF\Projects\Backhauls\index.cfm
Path Info : /Distribution/search
Host & Server: localhost:8300 OF080R8171V9X
Query String:
Referrer: http://localhost:8300/CF/Projects/Backhauls/index.cfm/Distribution/search?fwreinit=1
Browser: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30
Remote Address: 127.0.0.1
Form variables:
ISFORMSUBMITTED: false
ACCOUNTNUMBER:
BACKHAULNUMBER:
DISTRIBUTIONAMOUNT:
BACKHAULDATE:
VOUCHERNUMBER:
PURCHASEORDERNUMBER:
INVOICE:
SEARCH: Search
TRANSACTIONDATE:
DC:
RECEIVERNUMBER:
Session Storage:
Cookies:
CFID: 27702
CFTOKEN: 61e475f39a34a5da-02B77747-2268-1D08-2E79C8033F9C2E0C
BCSI-AC-7A58017B096123B9: 1BD88BF200000002xRgYDUyhiu4lOXISpwQhVlhZJp1rAAAAAgAAAESQaAGEAwAAAAAAAPIPHgA=
SESSIONID: PROJECT_27702_61e475f39a34a5da-02B77747-2268-1D08-2E79C8033F9C2E0C
Stack Trace:

coldfusion.runtime.UndefinedVariableException: Variable TEST is undefined.
	at coldfusion.runtime.CfJspPage._get(CfJspPage.java:303)
	at coldfusion.runtime.CfJspPage._get(CfJspPage.java:283)
	at coldfusion.runtime.CfJspPage._get(CfJspPage.java:271)
	at cfDistributionService2ecfc826941115$funcSEARCH.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\model\domain\services\DistributionService.cfc:97)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:517)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2547)
	at cfApplicationHelper2ecfm778785974$funcPAGERECORDS.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\includes\helpers\ApplicationHelper.cfm:43)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:517)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2547)
	at cfDistribution2ecfc783361978$funcSEARCH.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\handlers\Distribution.cfc:86)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:517)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:496)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:355)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2301)
	at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:389)
	at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2723)
	at cfController2ecfc319290547$funcINVOKER.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\frameworks\coldbox\3.1.dev\system\web\Controller.cfc:699)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2582)
	at cfController2ecfc319290547$funcRUNEVENT.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\frameworks\coldbox\3.1.dev\system\web\Controller.cfc:584)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:517)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:496)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:355)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2301)
	at cfColdbox2ecfc949270428$funcPROCESSCOLDBOXREQUEST.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\frameworks\coldbox\3.1.dev\system\Coldbox.cfc:243)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:491)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:337)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360)
	at cfApplication2ecfc867045667$funcONREQUESTSTART.runFunction(C:\WebRoot\Development\CF\Projects\Backhauls\Application.cfc:103)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:491)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:337)
	at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:88)
	at coldfusion.runtime.AppEventInvoker.onRequestStart(AppEventInvoker.java:258)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:349)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:94)
	at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
	at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126)
	at coldfusion.CfmServlet.service(CfmServlet.java:200)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
	at jrun.servlet.FilterChain.service(FilterChain.java:101)
	at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
	at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
	at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
	at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
	at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
	at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
	at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

Extra Information Dump
[N/A]

I wonder if that is a bug in CF9, going from script to non script outside of a function like that.

Well, as soon as I sent off my last message I figured out the problem.

I was passing a reference to an object method to another helper method (used for paging). The helper function later executes the passed in method. The problem, of course, is that it executes the function outside of the context of my service. Darn it all. I hadn’t ever done anything like that in ColdFusion before so I had no idea that it would execute the method the way it did. Ugh.

Sorry for wasting everyone’s time.

Thanks.

I am guessing that you are only writing the tag version of the functions due to the cfquery?

You do know that these can be written using script, not as pleasing to look at, but can be written in cfscript.

Yes, I do know that. In my opinion cfquery is still just a bit easier to use for long/complicated queries (which these are) so I’m still using it.

How?

You can still write it as complicated and long as you like, the only difference is that instead of doing this.

//Do some SQL stuff

You write it like this

saveContent variable=“local.queryText” {
//Do some SQL stuff
}
myQuery = new Query();
myQuery.setSQL(local.queryText);
myQuery.execute();

Oh wow, I didn’t realize you could use saveContent like that. Thanks for the info. I’ll definitely be using this in the future.

That is why I asked in the first place, not sure if you did or not.

cfquery still has the advantage of allowing CFIF statements within the SQL. I’ve not found a way to do that with savecontent or new Query() in cfscript.

Yes that is a problem, but still achievable. Treat the inner text of the query as a string that gets built up.

So what I showed before might become something like the following that I use for HQL in an application that I am working on.

savecontent variable=“local.hqlQuery” {
writeOutput(“select be from blogEntry as be LEFT JOIN FETCH be.Comment as comment join be.Blog.Space as s where s.uniqueUrl=:spaceurl and be.released = 1 " );
if(local.year != ‘’) {
writeOutput(” and year(be.posted)=:year");
local.criteria[‘year’] = local.year;
}
if(local.month != ‘’) {
writeOutput(" and month(be.posted)=:month");
local.criteria[‘month’] = local.month;
}
if(local.day != ‘’) {
writeOutput(" and day(be.posted)=:day");
local.criteria[‘day’] = local.day;
}
if(local.title != ‘’) {
writeOutput(" and be.alias=:alias");
local.criteria[‘alias’] = local.title;
}
writeOutput(" order by be.posted desc");
}

And as you can see it is still achievable, as I use HQL and ORM I will stress that with the query object, you will need to take into consideration of SQL injection and use parameters.