Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7859423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:54:20+00:00 2026-06-02T21:54:20+00:00

I have a component in Coldfusion8, that constructs a log of error messages and

  • 0

I have a component in Coldfusion8, that constructs a log of error messages and passes it to a variable in JSON to be picked up by Jquery.

I’m rebuilding this component when the user changes languages (reloads the page) like so:

HTML:

<a href="index.cfm?lang=EN">change to english</a>

In the reload I’m checking for lang and if specified am running this in Coldfusion:

<cfif isdefined("lang")>
   <cfset Session.lang= #lang#>

   <!--- rebuild error messages --->
   <cfinvoke component="services.errorMsg"
          method="createErrMsgsLog"         
          returnvariable="errMsgs">         
   </cfinvoke>
   <cfoutput><script type="text/javascript">var errorLog = '<cfoutput>#errMsgs#</cfoutput>';</script></cfoutput>
</cfif>

Question1:
Is there a better way to do this? From my little Coldfusion exp, CFINVOKE creates and discards objects, so this should be resource-friendly.

Question2:
How can I run this when the Application/Session starts? I tried running it from my application.cfc onSessionStart but I cannot trigger any Javascript alert/console from there, so I’m afraid nothing happens… Also there must be a better way than to plaster application.cfc with functions like this.

Thanks for some insights!

EDIT:
Halfway there: I can fire this when I change languages:

 <cfif isdefined("Sprachwechsel")>
   <cfset Session.Sprache = #Sprachwechsel#>
     <cfinvoke component="services.errorMsg" method="createErrMsgsLog"       returnvariable="Session.errMsgs">
     </cfinvoke>
     <cfoutput>
       <script type="text/javascript">var errorLog = '<cfoutput>#Session.errMsgs#</cfoutput>'</script>
     </cfoutput>

However I also want to fire this once from application.cfc. I can use the same code or the code below. Nothing happens.

 <cffunction name="onApplicationStart" returnType="boolean" output="false">
   <cfscript> 
      APPLICATION.strObjs = structNew();
      APPLICATION.strObjs.objErrMsg = createObject("component","services.errorMsg");    
   </cfscript>                  
   <cfreturn true />
 </cffunction>

 <cffunction name="onSessionStart" returnType="void" output="false">
    <cfscript>
    Session.sprache = "DE";
    Session.errMsgs = APPLICATION.strObjs.objErrMsg.createErrMsgsLog();
    </cfscript>
    <cfreturn true />
 </cffunction>

I have tried a gazillion variation, but Session.errMsgs just stays undefined if I check for it on the actual page. Any idea what I’m missing?

EDIT2:
Ok. I found the problem reading through here. When I changed my application name, I saw what wasn’t working and after fixing this, onSessionStart fired as expected. Quite a ride…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:54:22+00:00Added an answer on June 2, 2026 at 9:54 pm

    There probably is a better way to do it, but from the code you posted it is hard to tell which way is best for your particular situation. I assume your code sample is in your index.cfm?

    Here’s what you might do:

    1) in your onApplicationStart() method in Application.cfc cache your component:

    application.objErrMsh = createobject("component", "services.errorMsg");
    

    2) in onSessionStart() in your Application.cfc set session.lang to your default language and set session.errMsg var:

    session.lang = "DE";
    session.errMsg = application.objErrMsg.createErrMsgsLog(session.lang);
    

    (I assume here that your component’s return depends on user’s language setting. If not – what is the point in re-invoking the component on language change?)

    3) whenever you need to set your javascript errorLog var you can now do:

    <script type="text/javascript">var errorLog = <cfoutput>#session.errMsg#</cfoutput>;</script>
    

    4) when a user clicks on your ‘change language’ link, run this code:

    <cfparam name="url.lang" type="string" default="DE">
    <cfif url.lang neq session.lang>
      <cflock scope="session" type="exclusive">
      <cfset session.lang = url.lang>
      <cfset session.errMsg = application.objErrMsg.createErrMsgsLog(session.lang)>
      </cflock>
    </cfif>
    

    I.e. the above code will be at the top of your index.cfm page. You will also want to add some validation for url.lang value (e.g. that it is in the list of accepted values) so you don’t end up with all sorts of junk in there – always sanitize all user-supplied values.

    hth

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a component on an entity that may be null. This works in
So, given that I have an instance of this component: foo.cfc <cfcomponent> <cffunction name=locateMe>
I have a couple of places that have some code like this: <cfinvoke component=#application.path#cfc/eval_faculty
I have a ColdFusion component that will return some JSON data: component { remote
I have a component that I hand over a function public var func :
I have a component that is made up of various components such as a
I have a component that i want to store to an SQLite database. public
I have a component where i want to display a custom jtooltip. That is
I have a component with a number of properties that have various attributes Normally
I have a component called a TableDataViewer that contains the following pieces of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.