[Coldbox 5.0.0] Lucee 5.2.7 - Constant declarations in the Application scope

50 views
Skip to first unread message

Philippe Sambor

unread,
Jun 20, 2018, 11:49:21 PM6/20/18
to ColdBox Platform
When migrating from CF2016 engine to Lucee, it seems I can no longer use constants in the application scope. 

I set the following constants in Application.cfc, which loads them without error:

var Application.companyName = "alpha";

// Set application date and datetime database storage format
var Application.dbDatetimeFormat = "yyyy/mm/dd HH:nn";

But when I try to use those constants within my code such as "Application.dbDatetimeFormat" for example, Lucee triggers an error. The Adobe engine never did.

What is now the best practice to deal with constant declaration in Lucee?


Brad Wood

unread,
Jun 21, 2018, 12:07:48 AM6/21/18
to col...@googlegroups.com
Cfml has no concept of "constants" so I'm not sure what you're talking about. Also, why are you using the var keyword. I would expect that to create local.application.foo which clearly isn't what you want. Sounds like a bug in Adobe.

--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/5d5a0d62-2d3b-4508-b141-86e9681af835%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Philippe Sambor

unread,
Jun 21, 2018, 12:18:13 AM6/21/18
to ColdBox Platform
Hi Brad, I mean values that I can define in one place and refer to anywhere in my code such as a datetime format in the following function:

DateTimeFormat(arguments.UserAccountCreatedDatetime,"#Application.dbDatetimeFormat#");

which I use in every component that deals with date and time formats.

(var may not be needed in the declaration, I agree...).

Philippe Sambor

unread,
Jun 21, 2018, 2:52:52 AM6/21/18
to ColdBox Platform
Hi Brad, issues with Application.cfc are resolved. 

1 - I load a component called TenantCompany with Application.cfc, in which I set all the (constant value) parameters I need in the Application scope. 
2 - For Java components, I use the Coldbox Javaloader module.

Bottom line, Application.cfc is now super neat.

Brad Wood

unread,
Jun 21, 2018, 5:47:25 PM6/21/18
to col...@googlegroups.com
Glad to hear.  Maybe this goes without saying but for what it's worth, none of what you're doing is following ColdBox best practices.  WireBox should be creating all of these objects and the you should be asking WireBox for them or injecting them where necessary.  (The word singleton applies here to mean the same basic thing I think you meant by "constants")  

Now, if you're integrating ColdBox into a legacy site and just need these variables temporary as a stop gap until everything is converted, that is understandable.  But I just wanted to make it clear that in using ColdBox and Wirebox, you really shouldn't be creatinga by parts of your app in the Application.cfc.

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 



Philippe Sambor

unread,
Jun 21, 2018, 9:24:40 PM6/21/18
to ColdBox Platform
Brad, OK. I think I finally got it... a singleton object is in fact living in the application scope and managed by Wirebox, which is the reason why I no longer need to load any component whatsoever in Application.cfc.

Thanks!

Brad Wood

unread,
Jun 21, 2018, 9:47:17 PM6/21/18
to col...@googlegroups.com
Well, more specifically, the reason you shouldn't be creating CFCs in the Application.cfc file is because ColdBox/WireBox have conventions for creating CFCs.
The reason you shouldn't be directly creating CFC objects, is because WireBox should be doing all that for you (IOC stands for Inversion Of Control)
And yes, a singleton is persisted in WireBox, which is persisted ultimately in the application scope, so you don't ever have to worry about storing a CFC anywhere.  Simply tell WireBox how long you want that CFC to live and then, when you need an instance of it, ask WireBox to give it to you.  WireBox will take care of the rest.  IOC!

Note, WireBox is not just limited to CFC's, it can create instance of Java classes for you as well if you like.

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


Jason Durham

unread,
Jun 22, 2018, 10:10:12 AM6/22/18
to ColdBox List
I'm also a little surprised that "var application.foo =..." doesn't actually create that variable in local.application.foo.  You needn't use var when setting a variable in an explicit scope.

Jason Durham


Reply all
Reply to author
Forward
0 new messages