Skip to main content
glamorous_Wonder6C1C
Inspiring
May 18, 2011
Question

Problem with calling onApplicationStart() method

  • May 18, 2011
  • 4 replies
  • 2240 views

Hi all,

     I have a problem with calling application.cfc's methods from coldfusion template. The problem is like when i am calling "onapplicationstart" method inside a cfml template i getting the error shown below

The onApplicationStart method was not found.

Either there are no methods with the specified method name and argument types or the onApplicationStart method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

My code is like below.

Application.cfc

<cfcomponent hint="control application" output="false">

<cfscript>

this.name="startest";

this.applicationtimeout = createtimespan(0,2,0,0);

this.sessionmanagement = True;

this.sessionTimeout = createtimespan(0,0,5,0);

</cfscript>

<cffunction name="onApplicationStart" returnType="boolean">

    <cfset application.myvar = "saurav">

<cfset application.newvar ="saurav2">

    <cfreturn true>

</cffunction>

</cfcomponent>

testpage.cfm

<cfset variables.onApplicationStart()>

I have tried to call the above method in different way also like

1--- <cfset onApplicationStart()>

i got error like this

Variable ONAPPLICATIONSTART is undefined.

2---<cfset Application.onApplicationStart()>

The onApplicationStart method was not found.

Either there are no methods with the specified method name and argument types or the onApplicationStart method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity

Please help me out.

Thanks

Saurav

    This topic has been closed for replies.

    4 replies

    glamorous_Wonder6C1C
    Inspiring
    May 18, 2011

    thanks everyone.

    Inspiring
    May 18, 2011

    The methods in Application.cfc are no more accessible to external code than the methods in any other CFC. To call a CFC's methods, one needs to instantiate the CFC first.

    That said, if you had an onRequest handler which •included• your called-template, then the template code would be running in the context of the Application.cfc's methods, and you could just run onApplicationStart().

    So there's two options there.

    --

    Adam

    Community Expert
    May 18, 2011

    You can't just call methods in a CFC without a reference to that CFC. This includes methods in Application.cfc.

    What are you trying to do, exactly, anyway? You'd probably be better served by placing a call to onApplicationStart within onRequestStart in Application.cfc, if your goal is to refresh the application based on some condition:

    <cffunction name="onRequestStart">

         <cfif someCondition>

              <cfset onApplicationStart()>

         </cfif>

    </cffunction>

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    Participating Frequently
    May 18, 2011

    Put a hook in your onRequestStart() method of the Application.cfc that checks for the existence of a URL variable and calls onApplicationStart() as needed.  Something like:

    <cfif structKeyExists(url, "reinit")>

         <cfset onApplicationStart() />
    </cfif>