• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

onSessionEnd not working as expected

New Here ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

I have read many posts by people who have problems with onSessionEnd.  This is my first conversion of application.cfm to application.cfc and the onSessionEnd is not working with the CFFunction I am trying to invoke.

I guess what's hanging this up is how to properly call the component from the /lib/components/ folder where it resides.

When a user logs in I am creating a session array that tracks a jobNumber and the last_completed_step in that job.  There are multiple jobs in a users session.  At the end of the session I want to write the updated array data back to the DB.

I should make it clear that at present I look into my log file and see that the session is started - as coded in the onSessionStart shown below.  Furthermore, the onSessionEnd also writes to the log file when I take out the invocation of the component.  In other words if I just tell it to write "Session ended." to the log file I will see it in the log file. I have set current session timeout in CF Administrator and my app.cfc for 3 minutes for testing.

If I call the "giveMeAnswer" method in the jobState.cfc from a separate file (also at the root level) the giveMeAnswer method works properly and returns the value "I am a CFC."

If I move the jobState.cfc to the root level and set the component attribute to "jobState" I am also getting a return from the component.

<!--- Runs when your session starts --->

<cffunction name="onSessionStart" returnType="void" output="false">

    <!--- :: invoke all session variables | moved out of on session start  :: --->

    <cfinvoke component="#application.virtualPaths.cfcPath#system/sessionVars" method="init" />

    <cflog file="#This.Name#" type="Information" text="Session started.">

    </cffunction>

<!--- Runs when session times out --->

<cffunction name="onSessionEnd" returntype="void">

    <cfargument name="SessionScope" type="struct" required="true" />

    <cfargument name="ApplicationScope" type="struct" required="true" />

    <cfinvoke component="/lib/components/jobState" method="giveMeAnswer" returnvariable="returnFromCfc">

    </cfinvoke>

    <cflog file="#This.Name#" type="Information" text="Session ended.  #returnFromCfc#">

    <cfreturn />

</cffunction>

So, is it just not finding the component?  Any other ideas?

Thanks much, Jerry

TOPICS
Advanced techniques

Views

686

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

It appears that you are trying to access a session variable after the session has ended. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

Maybe I need to do something to pass the session.jobStepArray to the component?

Like the argument might be: sessionScope.session.jobStepArray

...session.jobStepArray being the array I want to process in the CFC.  I thought that since the session.jobStepArray already existed I would not need to "send" it to the function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

Read the docs, they will tell you all.

You can access shared scope variables as follows:

• You must use the SessionScope parameter to access the Session scope. You  cannot reference the Session scope directly; for example, use  Arguments.SessionScope.myVariable, not Session.myVariable.

• You must use the ApplicationScope parameter to access the Application  scope. You cannot reference the Application scope directly; for example,  use Arguments.ApplicationScope.myVariable, not Application.myVariable.  Use a named lock when you reference variables in the Application scope,  as shown in the example.

• You can access the Server scope directly; for example,  Server.myVariable.

• You cannot access the Request scope.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

Owain,

Thanks for the info.  I have read about passing in the session scope but I am probably not thinking of this correctly.

What I mean is that the method that onSessionEnd calls in the cfc to write the data from the session.jobStepArray to the database already exists.  So, I wrote a method that does not take any arguments.  My concept was that I just want to write whats in the session array to the database and since the array already exists in session then the method will just act upon that array.  Does it's thing.  Then end.

It appears that my thinking is flawed in that I really do need to pass the session.jobStepArray as an argument to the method when calling the CFC.

And, I need to make sure that I've passed in the SessionScope and then send the argument of:

    Arguments.SessionScope.session.jobStepArray to the component method.

Does that make sense anyone?  (besides me)

J

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

It probably won't make any difference because the session will have ended.  To test this put this into your onSessionEnd function.

<cfdump var = "#session#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

Dan, I'm trying it right now - had a meeting.

So, are you saying that there is not a way to get the session.jobStepArray values at/to onSessionEnd?  Or ANY session values and do something with them at onSessionEnd.  I'm stumped then.

Is there another method that you can suggest for this?  That is other than writing each value to the database separately at the time of execution.

J

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

So, are you saying that there is not a way to get the session

Well... no.  You're in the onSessionEND handler, so intrinsically the session has ended.  That's the whole point.

However, you might want to read Owain's post, and then read the docs he pointed you do.  That pretty much explains how it all works.  But you do actually need to read the docs: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d40.html

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2011 Jun 15, 2011

Copy link to clipboard

Copied

LATEST
    <cfinvoke component="/lib/components/jobState" method="giveMeAnswer" returnvariable="returnFromCfc">  

I'm surprised that way of referencing a CFC works.  You should be using dot notation, not giving CFINVOKE a path.  This, though, has nothing to do with your issue, it's just an observation.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0a.html

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation