-1

I am trying to deconstruct an array loop created by some one and they had instructions on how to call but if I do that value, I am being ended up in an error

Here is the code

<cfloop from="1" to="#ArrayLen(variables.elementObjectsArray[e].items)#" index="o">
    <option
        <cfif ArrayLen(variables.elementObjectsArray[e].items[o]) eq 3>
            class="#variables.elementObjectsArray[e].items[o][3]#"
        </cfif>
        value="#variables.elementObjectsArray[e].items[o][1]#"
        <cfif session.form[e] EQ "#variables.elementObjectsArray[e].items[o][1]#">
            selected="selected"
        </cfif>
    >
        #variables.elementObjectsArray[e].items[o][2]#
    </option>
</cfloop>

and they mention it to call it this way

// a 2-d array of items if type=select: ["optionValue","optionText","optionClass"]

here is dump of the array (variables.elementObjectsArray[e].items) (from comments)

enter image description here

i did that way, but i am always ending up in error, anyone can guide what i am missing here

This is the error in stack

<td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:pointer;" title="click to collapse">StackTrace</td>
                    <td>
                    coldfusion.runtime.NonArrayException: Object of type class java.lang.String cannot be used as an array
    at coldfusion.runtime.Cast._List(Cast.java:1388)
    at coldfusion.runtime.CFPage.ArrayLen(CFPage.java:705)
    at cfForm2ecfc910767489$funcSHOWFORM._factor2(C:\ColdFusion2016\cfusion\wwwroot\water\cfcs\common\Form.cfc:289)
    at cfForm2ecfc910767489$funcSHOWFORM._factor3(C:\ColdFusion2016\cfusion\wwwroot\water\cfcs\common\Form.cfc:264)
    at cfForm2ecfc910767489$funcSHOWFORM._factor4(C:\ColdFusion2016\cfusion\wwwroot\water\cfcs\common\Form.cfc:259)
    at cfForm2ecfc910767489$funcSHOWFORM._factor5(C:\ColdFusion2016\cfusion\wwwroot\water\cfcs\common\Form.cfc:258)
    at cfForm2ecfc910767489$funcSHOWFORM.runFunction(C:\ColdFusion2016\cfusion\wwwroot\water\cfcs\common\Form.cfc:235)
    at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:493)
    at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:389)
    at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
    at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:340)
    at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:235)
    at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:654)
    at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:443)
    at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:413)
    at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3247)
    at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3224)
    at cfregistration2ehtml927971521.runPage(C:\ColdFusion2016\cfusion\wwwroot\water\registration.html:53)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:254)
    at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:743)
    at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:573)
    at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:3851)
    at cfsystem2ehtml2885719.runPage(C:\ColdFusion2016\cfusion\wwwroot\water\system.html:7)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:254)
    at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:743)
    at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:573)
    at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:3851)
    at cfindex2ehtml2139074217.runPage(C:\ColdFusion2016\cfusion\wwwroot\water\index.html:237)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:254)
    at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:743)
    at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:573)
    at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
    at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)
    at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:484)
    at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)
    at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
    at coldfusion.filter.PathFilter.invoke(PathFilter.java:153)
    at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
    at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
    at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
    at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
    at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)
    at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
    at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
    at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
    at coldfusion.CfmServlet.service(CfmServlet.java:223)
    at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
    at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:121)
    at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:616)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1634)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745) 
                    </td>
naz
  • 31
  • 4
  • 5
    What is the error and which line is throwing it? Can you show us a dump of the array (variables.elementObjectsArray[e].items)? – CFMLBread Oct 05 '22 at 20:58
  • here it is https://prnt.sc/p23wYbzqYMG5 – naz Oct 05 '22 at 21:19
  • 2
    What is the error you are receiving and on what line (as @CFMLBread asked). A full example we can run on trycf.com that includes the data and code that errors would be very helpful. – Brad Wood Oct 05 '22 at 22:31
  • Taking a wild guess here: `session.form[e]` might be the problem, because `session.form` is empty or doesn't have any data für index/key `e`. This loop can also probably be simplified by using `cfloop array index` over `cfloop from to index`. – Alex Oct 06 '22 at 00:17
  • please guide, i can send array of objects to the items code, but i need some guidance how can i reflect the change in the options, instead of the arrays being send – naz Oct 06 '22 at 13:13
  • 1
    You still have not shared the error message that you are getting. We cannot help if we do not know what the error is. This is why it is best to have a full example of code to demonstrate the error. – Miguel-F Oct 06 '22 at 14:45
  • It might be because in some cases `variables.elementObjectsArray[e].items` appears to be a one dimensional array and in others it's 2D. – Dan Bracuk Oct 06 '22 at 16:47
  • I think `variables.elementObjectsArray[e].items[o]` is not an array, and therefore does not have an `arrayLen`. `variables.elementObjectsArray[e].items` *is* an array, but but `variables.elementObjectsArray[e].items[o]` are strings. – mykaf Oct 06 '22 at 21:27
  • i added the error i am facing @Miguel-F – naz Oct 08 '22 at 14:53
  • figured out it should go as: `items = [['M,'M'],['F','F']]` – naz Oct 08 '22 at 17:54

1 Answers1

1

figured out it should go as: items = [['M,'M'],['F','F']]

naz
  • 31
  • 4
  • some people don't know why they mark the post negative because they do not want to answer or block the post, at least give it a shot, if not just watch what happens with question, – naz Oct 09 '22 at 14:38