Skip to main content
Participant
October 6, 2009
Question

CFML Structure Undefined.

  • October 6, 2009
  • 2 replies
  • 1038 views

Morning,

Within a CFC that is loaded into the application scope I am attempting to translate some text in the session scope via Googles Translation service... I am getting (intermintanly) the below error message and it's driving me nutz. Any help/pointers would be great! I am the only programmer here and there is no one to turn too 😐

Element RESPONSEDATA.TRANSLATEDTEXT is undefined in a CFML structure referenced as part of an expression. See Stack Trace Below Code.

----Index.cfm----

<cfcase value="setlanguage">
    <cflock name="SwitchLanguages" timeout="10" type="exclusive">
      <cfset application.gen.setLang(form.changeLang)>
    </cflock>
    <cflocation url="index.cfm?#form.currentURL#">
  </cfcase>

---general.cfc----

<cffunction name="setLang" access="public" returntype="void" output="false">
    <cfargument name="var_language" type="string" required="yes" />

<cfif arguments.var_language eq 'en'>
    <cfset var_lang = 'en'>
    <cfset session.user_language = 'en'>
<cfelseif arguments.var_language neq 'en'>
    <cfset var_lang = arguments.var_language>
    <cfset session.user_language = arguments.var_language>
</cfif>

<!--- Text --->
<cfparam name="hbn01" default="Bread">
<cfparam name="hbn02" default="Toast">
<cfparam name="hbn03" default="Orange">

<cfif var_lang neq 'en'>
  <cftry>
  <cfhttp url="
http://ajax.googleapis.com/ajax/services/language/translate" charset="utf-8" method="post" result="restDoc" throwonerror="yes">
  <!--- Header and Body Nav --->
  <cfhttpparam type="Header" name="charset" value="utf-8" />
  <cfhttpparam type="header" name="Accept-Encoding" value="*" />
  <cfhttpparam type="header" name="TE" value="deflate;q=0">
  <cfhttpparam type="url" name="v" value="1.0">
  <cfhttpparam type="url" name="q" value=#hbn01#>
  <cfhttpparam type="url" name="q" value=#hbn02#>
  <cfhttpparam type="url" name="q" value=#hbn03#>

  <cfhttpparam type="url" name="langpair" value="en|#var_lang#">
  </cfhttp>
  <cfset  deJSON = #DeserializeJSON(restDoc.filecontent,false)#>
  <!--- Error Catching --->
  <cfif DeserializeJSON(restDoc.Filecontent).responseStatus eq '200'>
  <cfset allGood = 'No Errors Recieved'>
  </cfif>
  <cfcatch>
    <cfset var_lang = 'en'>
  </cfcatch>
  </cftry>
</cfif>

<cfif var_lang neq 'en'>
     <cfset session.nav.n1.main = #deJSON.responseData[1].responseData.translatedText#>
     <cfset session.nav.n2.main = #deJSON.responseData[2].responseData.translatedText#>
     <cfset session.nav.n3.main = #deJSON.responseData[3].responseData.translatedText#>

<cfelse>
  <!--- Defualt Text --->
  <cfset session.nav.n1.main = #hbn01#>
  <cfset session.nav.n2.main = #hbn02#>
  <cfset session.nav.n3.main = #hbn03#>

</cfif>

STACK TRACE

coldfusion.runtime.UndefinedElementException: Element RESPONSEDATA.TRANSLATEDTEXT is undefined in a CFML structure referenced as part of an expression. at coldfusion.runtime.DotResolver.resolveSplitNameInMap(DotResolver.java:108) at coldfusion.runtime.CfJspPage._resolve(CfJspPage.java:1494) at coldfusion.runtime.CfJspPage._resolveAndAutoscalarize(CfJspPage.java:1712) at coldfusion.runtime.CfJspPage._resolveAndAutoscalarize(CfJspPage.java:1704) at cfgeneral2ecfc1724243991$funcSETLANG._factor19(Z:\Private_\xyz.company.com\html\general.cfc:980) at cfgeneral2ecfc1724243991$funcSETLANG._factor22(Z:\Private_\xyz.company.com\html\general.cfc:957) at cfgeneral2ecfc1724243991$funcSETLANG._factor35(Z:\Private_\xyz.company.com\html\general.cfc:956) at cfgeneral2ecfc1724243991$funcSETLANG.runFunction(Z:\Private_\xyz.company.com\html\general.cfc:821) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:360) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:324) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:192) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:448) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:308) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2272) at cfindex2ecfm557167804._factor8(Z:\Private_\xyz.company.com\html\index.cfm:22) at cfindex2ecfm557167804._factor15(Z:\Private_\xyz.company.com\html\index.cfm:19) at cfindex2ecfm557167804._factor16(Z:\Private_\xyz.company.com\html\index.cfm:15) at cfindex2ecfm557167804.runPage(Z:\Private_\xyz.company.com\html\index.cfm:1) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:370) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:273) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:86) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126) at coldfusion.CfmServlet.service(CfmServlet.java:175) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

    This topic has been closed for replies.

    2 replies

    October 7, 2009

    I suspect that you are new to programming...

    General coding style is not good, use of var scopes is not good...

    When you expect an array of elements it is always best to loop through them and check the length o fthe array at runtime...

    fstanleyAuthor
    Participant
    October 7, 2009

    Not only does Google translate send back a response status of 200 on the file but they also return a response code on every element translated.

    When the element is referenced and it contains no value you will get that error message. I missed it before since I was processing 52 different elements. In turn I fix this by wrapping the translatedText with each own translated texts' responceStatus... Not pretty I will have to put it all in a cfscript SOMEDAY!

    <cfif deJSON.responseData[1].responseStatus eq '200'><cfset session.nav.n1.main = #deJSON.responseData[1].responseData.translatedText#><cfelse><cfset session.nav.n1.main = #hbn01#></cfif>