I have this code in my cfm, which works
<cfif not StructIsEmpty(form)>
<cfset larray = user.getArray() />
<cfloop collection="#form#" item="key">
<cfif left(key,4) eq "UPD_">
<cfset x = listLast(key,"_") />
<cfset y = evaluate(0,key) />
<cfloop index="j" from="1" to="#arrayLen(larray)#">
<cfif (larray[j][1] eq x) and (larray[j][3] neq y)>
<cfset larray[j][3] = y />
<cfif not LSIsNumeric(larray[j][3])>
<cfset larray[j][3] = "0" />
</cfif>
<cfset larray[j][4] = "update" />
</cfif>
</cfloop>
</cfif>
</cfloop>
<cfloop collection="#form#" item="key">
<cfif left(key,4) eq "DEL_">
<cfset x = listLast(key,"_") />
<cfloop index="k" from="1" to="#arrayLen(larray)#">
<cfif larray[k][1] eq x>
<cfset larray[k][4] = "delete" />
</cfif>
</cfloop>
</cfif>
</cfloop>
<cfset user = createObject("component", "cfc.User").init(
identifier = FormatBaseN(form.id,10),
array = larray
) />
</cfif>
<form name="usform" method="POST">
<cfset array = user.getArray() />
<cfoutput>
<cfloop index="i" from="1" to="#arrayLen(array)#">
<table>
<tr>
<td><input type="text" name="upd_#array[i][1]#" maxlength="6" size="6" value="#array[i][3]#" /></td>
<td><input type="checkbox" name="del_#array[i][1]#" /></td>
</tr>
</table>
<input type="hidden" name="id" value="#user.getIdentifier()#" />
</cfoutput>
</form>
I have put it into a cfc to seperate my logic and my view and i am trying to make it more generic
<cfcomponent name="ArrayManager" output="false">
<cffunction name="init" hint="constructor" output="false" returntype="ArrayManager">
<cfargument name="user" type="User" required="true" hint="User bean" />
<cfargument name="form" type="Struct" required="true" />
<cfset variables.instance.array = arguments.user.getArray() />
<cfset variables.instance.form = arguments.form />
<cfreturn this />
</cffunction>
<cffunction name="update" access="public" output="true" returntype="boolean">
<cfargument name="structstring" type="String" required="true" />
<cfargument name="seperator" type="String" required="true" />
<cfset var x = "0" />
<cfset var y = "0" />
<cfloop collection="#variables.instance.form#" item="key">
<cfif key eq "#arguments.structstring#">
<cfset x = listLast(key,"#arguments.seperator#") />
<cfset y = evaluate(0,key) />
<cfloop index="j" from="1" to="#arrayLen(variables.instance.array)#">
<cfif (variables.instance.array[j][1] eq x) and (variables.instance.array[j][3] neq y)>
<cfset variables.instance.array[j][3] = y />
<cfif not LSIsNumeric(variables.instance.array[j][3])>
<cfset variables.instance.array[j][3] = "0" />
</cfif>
<cfset variables.instance.array[j][4] = "update" />
</cfif>
</cfloop>
</cfif>
</cfloop>
<cfset arguments.user.init(array = variables.instance.array) />
<cfreturn true />
</cffunction>
<cffunction name="delete" access="public" output="false" returntype="boolean">
<cfargument name="structstring" type="String" required="true" />
<cfargument name="seperator" type="String" required="true" />
<cfset var x = "0" />
<cfloop collection="#variables.instance.form#" item="key">
<cfif key eq "#arguments.structstring#">
<cfset x = listLast(key,"#arguments.seperator#") />
<cfloop index="k" from="1" to="#arrayLen(variables.instance.array)#">
<cfif variables.instance.array[k][1] eq x>
<cfset variables.instance.array[k][4] = "delete" />
</cfif>
</cfloop>
</cfif>
</cfloop>
<cfset arguments.user.init(array = variables.instance.array) />
<cfreturn true />
</cffunction>
</cfcomponent>
And my new cfm
<cfif not StructIsEmpty(form)>
<cfset arraymanager = createObject("component","cfc.ArrayManager").init(user,form) />
<cfset seperator = "_" />
<cfset structstring = "UPD" />
<cfset arraymanager.update(structstring,seperator) />
</cfif>
...
It fails, i get this error message
The CFML compiler encountered an unexpected coldfusion.compiler.CompilerInternalException exception. The reason for this was: Unable to complete CFML to Java translation. Occurred at:
. . .
The error occurred in C:\path\to\document\root\cfc\ArrayManager.cfc: line 21
Called from C:\path\to\document\root\cfc\update-emp.cfm: line 66
Called from C:\C:\path\to\document\root\cfc\update-emp.cfm: line 6619
: <cfif key eq "#arguments.structstring#">
:
20
21: <cfset y = evaluate(0,key) />
:
22
23 `:
What am i doing wrong or is there a better way to accomplish what i am trying to do (showing database content in a table and updating(Update and Delete) the database content through the same table)