2

I recently installed ColdFusion 2018 at work and have been frustrated by the inability to get scope working correctly. As usual I put all my .cfcs into the /CFC folder, and none of them will execute without a blank application.cfm file in that folder. I have tried extending application, including application, proxy extending application, moving the CFCs to the root folder only gets me syntax error on JSON. I have read every article that I can find for the past two weeks and I am still unable to understand why scope will not work. It seems I can set session variables within the /CFC folder, but they are not available outside the folder? I have not worked with CF for a few years, but consider myself versed, and for the life of me cannot get this working. its probable that I am missing the forest due to trees, but if anyone would be willing to assist, I would be grateful.

instantiated object;

application.SessionMgr = CreateObject(this.obj,'CFC.SessionMgr').init('session');

proxy call;

cfajaxproxy cfc="CFC/SessionMgr"       jsclassname="SessionMgr";

return is correct;

var s = new SessionMgr();
       var setReport = s.setValue('ReportID', document.getElementById('cboReportKey').value);
       alert(setReport);

however even manually setting session.ReportID = 7 will not persist outside the folder.

here is the SessionMgr.init

this is the init;

<cffunction name="init" access="public" returntype="SessionMgr" output="no" hint="I instantiate and return this object.">
        <cfargument name="scope" type="string" required="yes">
        <cfargument name="requestvar" type="string" default="SessionInfo">
            <cfset var scopes = "application,Client,Session">
            <cfif Not ListFindNoCase(scopes, arguments.scope)>
                <cfthrow message="The scope argument for SessionMgr must be a valid scope (#scopes#)." type="MethodErr">
            </cfif>
            <cfset variables.scope = arguments.scope>
            <cfset variables.requestvar = arguments.requestvar>
            <cfset updateRequestVar()>
        <cfreturn this>
    </cffunction>

and the setValue fn

<cffunction name="setValue" access="remote"  hint="I set the value of the given user-specific variable." returntype="string">
        <cfargument name="variablename" type="string" required="yes">
        <cfargument name="value" type="any" required="yes">
            <cfset var val = arguments.value />
            <cfset SetVariable("#arguments.variablename#", val) />
            <cfset r =  Evaluate(arguments.variablename) />
        <cfreturn r />
    </cffunction>
Shawn
  • 4,758
  • 1
  • 20
  • 29
BigBear
  • 59
  • 4
  • 1
    The session will support only inside your application only. ( Your root of an project ). The outside of session scope search about application of parent folder. Like whether the parent folder have any application cfc or not , If it's having app.cfc then check whether it's having session enabled or not etc.. – Kannan.P May 07 '19 at 14:10
  • I do have application.cfc in root, where I instantiate session scope, timeout etc. I simply dont understand why any attempt to change a session variable using a cfc function inside the /CFC folder does not persist outside the folder – BigBear May 07 '19 at 14:15
  • in CF 8, 9 and 10 you never needed a .cfc of .cfm in the CFC folder, it simply inherited, now I am on cf 2018 and NOTHING in the CFC folder will work without the blank application.cfm file, and all attempts to extend the root application.cfc only wreaks havok with no improvement – BigBear May 07 '19 at 14:17
  • Are you using tag ? if yes please add sessionManagement = "yes|" then only you can access session scopes in entire applications. – Kannan.P May 07 '19 at 14:34
  • The sessionMgr lives in the application scope, but the init() call takes a session as an argument. How would this architecture support multiple sessions? Also, the first argument of createObject() seems incorrect. It should just be `createObject("cfc.sessionMgr");` On another note, I would try eliminating the ajax proxy stuff and making sure you can get the correct result on the server side first. Once you've verified that, then try using the ajax stuff, though I would recommend not using the built-in coldfusion ajax functionality and doing it yourself using jQuery or a similar library. – Redtopia May 07 '19 at 14:43
  • this.obj is simply a localized variable defined as 'component', it is part of a larger service factory of cfcs that are available in application scope, and yes, I have tried hard calls using application.SessionMgr.setValue('ReportID', val), the ajax proxy is simply one of the many, many attempts to simply set a session.ReportID to the selected DOM value so if the user returns it can preselect the report. the init allows for client, request, and session, the example provided is simply one of many, many tries to get session scope to persist outside the /CFC folder. – BigBear May 07 '19 at 14:48
  • this.sessionmanagement = "true"; is defined in onApplicationStart function. and no, I am not using tag inside application.cfc – BigBear May 07 '19 at 14:51
  • What type of file system are you using, and is it `application.cfc` or `Application.cfc`? In the past, I have had the capitalization bite me when moving to a case-sensitive server OS. – Shawn May 07 '19 at 15:11
  • application.cfc, but this is not the issue, as everything else seems to operate correctly, the problem seems to be that setting any scoped variables within the /CFC folder using functions, or function calls outside the /CFC folder do not allow any scope to persist other than from within the /CFC folder. It makes no sense that application, client, request and session are editable within the folder but do not persist outside the folder. – BigBear May 07 '19 at 15:19
  • @BigBear You have an `application.cfc` in the root that sets up your application, and then a blank `application.cfm` in your `/CFC` folder? What happens if you remove that extra `app.cfm` or dump the `application` scope from within the `/CFC` folder? It sounds like either your application isn't getting set or it's getting overridden. How are you instantiating your CFCs? What is `this.object`? Create a new folder with a simple CFC in it and try to instantiate it from your root. Does it work? – Shawn May 07 '19 at 15:31
  • If I remove the application.cfm file inside the /CFC folder, then NOTHING in the /CFC folder works. I am instantiating the cfcs into a service factory in application scope shown above. 'this.obj' is simply a variable that is defined as 'component' for shorthand. all the CFCs are available in the application scope, however application.SessionMgr.setValue('ReportID', 5) does indeed set session.ReportID INSIDE the /CFC folder, via dumps, however, it does not actually update session scoped and available after set. I am researching if I should be using J2EE variables instead. – BigBear May 07 '19 at 15:36
  • I have been using CF since 4.0 and have never run into this issue, I am leaning towards this being an admin setting issue, or some solution to extend the applicaiton.cfc into the /CFC folder, however, I have exhausted all tries on that front, I run CF10 @ home and it works fine testing this new API, but on cf 2018 , no bueno. – BigBear May 07 '19 at 15:40
  • The `Application.cfc` should automatically extend into any folder underneath it that doesn't have another `Application.cfc/.cfm` in it, so something else is blocking that application. Do you have any other framework running in this application, or is there an odd mapping for "/CFC"? That was why I suggested trying to duplicate the behavior from another folder. – Shawn May 07 '19 at 15:59
  • If you place an `Application.cfc` file within the `CFC` folder then it will not share the same application/session scope as the root folder (unless you extend that one or use the same name). AFAIK ColdFusion 2018 did not change anything in regards to how the application architecture works. It should work the same. There must be something else in play here. Like @Shawn mentioned, try updating the session from some other sub-folder and see if it works. – Miguel-F May 07 '19 at 16:02
  • so I created a test.cfm and did cfdump of application scope, and then put this test.cfm inside the /CFC folder, and it dumps fine, I also removed the application.cfm file from the same folder, ok, good, its inheriting properly now. I also moved client variable storage to CDATA instead of registry. and now I encountered a new problem, which I think is related. the service factory will dump application.Reports.GetShowAll(), but binding a cfselect to cfc:CFC.Reports.GetShowAll() gives me uncaught syntaxerror: parseJSON. I ripped everything off the page for one e.g. to test on. – BigBear May 07 '19 at 16:18

1 Answers1

0

ok, after trying everything, heres the solution. extending by proxy doesnt work for this situation, tried that. What finally worked was creating an application.cfc IN the /CFC folder and stripping out all functional components from the /root application.cfc and simply ensuring the application name was the same in the stripped down version in /CFC folder as the /root cfc name. This apparently psuedo extends all the functionality from the /root application.cfc and makes everything available to the framework in the /CFC folder. Thanks to everyone here helping to get me to think outside my wheelhouse and resolving this issue.

BigBear
  • 59
  • 4
  • 2
    It's good you've got this working again, but I don't think we've identified the actual problem. We've just executed a hack to make it work right now. You aren't really pseudo extending the base App.cfc, you're just reusing the name in a new application in a nested folder. There's still something causing interference and preventing the base application from working normally. Sometime in the future, if the Application name changes or something changes in the way `Application.cfc` is handled, this'll be back to figuring out why the CFCs stopped working. – Shawn May 07 '19 at 19:53
  • 1
    +1 to @Shawn comment. You should not need this to make it work. It should be working as you expect. Something else is wrong here. – Miguel-F May 07 '19 at 20:18
  • I completely agree with both statements, this is a hack. and it should not be required in the first place. I am still leaning towards some cfadmin setting that is isolating the application scope and hence the associated scopes. I will continue development moving forward and if any new solution arises then I will update this thread – BigBear May 08 '19 at 12:30
  • Nothing to do with your question, but I wouldn't recommend using `SetVariable()` and `Evaluate()` that way. Especially with a "remote" method. It could potentially allow a malicious user to alter other things beside their own session, for example application variables! – SOS May 29 '19 at 18:00
  • intranet only, so security is not an issue – BigBear May 29 '19 at 18:03
  • Security is always a concern, just different concerns than public facing apps. But your app, your responsibility... ;-) – SOS May 29 '19 at 19:12