Application variables set in applicationStartEvent()

71 views
Skip to first unread message

c.a

unread,
Dec 19, 2011, 3:24:57 PM12/19/11
to taffy...@googlegroups.com
Hello all,

just starting with Taffy and I am having some issues that seem rather basic in nature but am unable to solve.

I wish to cache references to several components in the application scope as I have done for quite a long time pre-Taffy. Now for some reason when I attempt to create a reference inside the applicationStartEvent() they do not seem to be available from within my Taffy resources. Then I tried simply setting a single application variable inside applicationStartEvent() "application.DSN" to be user in one of my queries inside a Taffy resource and it tells me the variable is undefined.

Am I missing something?

Any help is greatly appreciated.

Thanks!

-chris

Adam Tuttle

unread,
Dec 19, 2011, 3:27:04 PM12/19/11
to taffy...@googlegroups.com
Hi Chris,

That does sound particularly weird. It sounds like it should be working. Can you share your code?

Adam

chris.alvarado

unread,
Dec 19, 2011, 3:47:44 PM12/19/11
to taffy...@googlegroups.com
my Application.cfc:

<cfcomponent extends="taffy.core.api">
<cfscript>
this.name = "MyAPI";

// do your onApplicationStart stuff here
function applicationStartEvent(){
application.DSN = "MyDSN";
}

// do your onRequestStart stuff here
function requestStartEvent(){}

// this function is called after the request has been parsed and all request details are known
function onTaffyRequest(verb, cfc, requestArguments, mimeExt){
// this would be a good place for you to check API key validity and other non-resource-specific validation
return true;
}

// called when taffy is initializing or when a reload is requested
function configureTaffy(){
setDebugKey("debug");
setReloadKey("reload");
setReloadPassword("true");

// Usage of this function is entirely optional. You may omit it if you want to use the default representation class.
// Change this to a custom class to change the default for the entire API instead of overriding for every individual response.
setDefaultRepresentationClass("taffy.core.genericRepresentation");
}
</cfscript>
</cfcomponent>

UserMember.cfc

<cfcomponent extends="taffy.core.resource" taffy:uri="/user/{UserID}" hint="">

<cffunction name="Get" access="public" output="false">
        <cfargument name="UserID" required="yes" type="string">
        
        
<cfquery name="selUser" datasource="#application.DSN#">
SELECT *
            FROM [User]
            WHERE UserID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.UserID#" />
</cfquery>
<cfif selUser.recordCount gt 0>
<cfreturn representationOf(selUser).withStatus(200) />
<cfelse>
<cfreturn noData().withStatus(404) />
</cfif>
</cffunction>

</cfcomponent>
It's fairly vanilla code. Once I can get the application variable to output correctly I plan on storing a reference to several of my CFCs in the application scope.

c.a

unread,
Dec 19, 2011, 5:17:23 PM12/19/11
to taffy...@googlegroups.com
I figured it out. And now I feel stupid.

I hadn't defined an applicationTimeout. Once I did so, my application variables began working as did my component reference.

However, what is the best way to force the applicationStartEvent() to be called again? If I change something in one of my cached CFCs I have to stop / start CF in order to get the changes to take effect. I thought appending reload=true to the end of my request url would do it, but it doesn't seem to.

Adam Tuttle

unread,
Dec 19, 2011, 5:34:03 PM12/19/11
to taffy...@googlegroups.com
Glad you figured it out. ?reload=true should do it with the config you posted -- it's one of the first things that gets checked. It does have to be a query string variable though, not like /foo/bar/reload/true.

Adam

c.a

unread,
Dec 19, 2011, 6:09:09 PM12/19/11
to taffy...@googlegroups.com
Odd. That's what I'm doing and I still have to keep restarting Cold Fusion server in order to be able to access any new application variables that are set in the applicationStartEvent().

Adam Tuttle

unread,
Dec 19, 2011, 7:02:20 PM12/19/11
to taffy...@googlegroups.com

I just took a look at the code and this is definitely a bug. I'll push a fix for it soon, hopefully tonight after the kids go to bed. :)

Adam

Matthew Gersting

unread,
Dec 19, 2011, 7:21:41 PM12/19/11
to taffy...@googlegroups.com, taffy...@googlegroups.com
I don't think I've had any problem with this (except with ColdSpring beans not refreshing). Adam, you say you see a bug? Is this something that's been introduced at some point relatively recently?

c.a

unread,
Dec 20, 2011, 12:53:32 AM12/20/11
to taffy...@googlegroups.com
I believe I found the bug you are referring to.

in api.cfc at line 36 (inside the onRequestStart() method)

I added a call to the applicationStartEvent() method and all seems to be functioning correctly now.

I would have waited for the "official fix" but I need to get moving with a project I am working on using the Taffy framework.

Really liking the simplicity thus far, even though I am still learning the ins and outs.

Adam Tuttle

unread,
Dec 20, 2011, 8:08:05 AM12/20/11
to taffy...@googlegroups.com

Matthew, I don't think the bug applies to 1.1rc1 if you're using that version, just 1.0.

c.a

unread,
Dec 20, 2011, 9:37:53 AM12/20/11
to taffy...@googlegroups.com
I updated to the 1.1rc1 release and you're correct, the same issue is not occurring.

Adam Tuttle

unread,
Dec 20, 2011, 1:53:10 PM12/20/11
to taffy...@googlegroups.com
Just pushed the change,it should be fixed in 1.0 now too.

Adam
Reply all
Reply to author
Forward
0 new messages