Persistant component in session scope Calling functions from cfm page
Hi, (Using Coldfusion 9.01 Standard)
Ik have slight problem using a persistent component in the session scope. i'm using inside the component a global called this.cartarray where all articles are stored on an user session. Multiple functions are declared in the component that manipulates the this.cartarray. One of the functions is converting the array to a Query object for easy showing on a cfm page. Example: Session.myShoppingCart = myShoppingCart.cfc
<cfcomponent hint="ShoppingCart">
<!--- global definition --->
<cfset This.Cartarray = ArrayNew(1)>
<cffunction name="List">
<cfset q = QueryNew("CartItemID,ItemNo")>
<cfset var localCartArray = arrayNew(1)>
<cfset localCartArray = This.CartArray>
<cfloop from="1" to="#ArrayLen(localCartArray)#" index="i">
<cfset QueryAddRow(q)>
<cfset QuerySetCell(q, "CartItemID", localCartArray.CartItemID)>
<cfset QuerySetCell(q, "ItemNo", localCartArray.ItemNo)>
</cfloop>
<cfreturn q>
</cffunction>
<cffunction name="EmptyCart">
<cfset ArrayClear(This.CartArray)>
</cffunction>
</component>
Here the example of the myShoppingCart.cfm
<!--- On the Beginning --->
<cfset var getCart = Session.myShoppingCart.List()>
<!--- After that the manipulate function in case of a form submit --->
<cfif structKeyExists(FORM,"X") AND FORM.X eq 1>
<cfset temp = Session.myShoppingCart.EmptyCart()>
</cif>
<!--- --->
<!--- Viewing the Cart --->
<cfoutput>
<table>
<tr>
<th>CartItemID</th>
<th>ItemNo</th>
</tr>
<cfloop query="getCart">
<tr>
<td>#CartItemID#</td>
<td>#ItemNo#</td>
</tr>
</cfloop>
</table>
</cfoutput>
<!--- --->
</cfloop>
What is wrong with the flow because i get an Row number 0 Out of bounds exception using the List() function (On QuerySetCell).
Thanks in advance,
Chris
