The upshot here is that the EventContext CFC (this is the "event"
object that is passed into message listener functions in the
controller) has seen significant changes in Model-Glue 3. I took a
look at the getAllArguments() method in MG 2, and it uses the
duplicate() function to return a copy of the arguments structure,
whereas the MG 3 method returns a reference instead.

In your controller, a variable assignment is also a reference, so your
"args" variable is referring to the internal arguments structure of
the event handler in question. Therefore, when you delete one of the
argument keys, you are modifying the internal state of the containing
event handler object, and once an argument is removed, subsequent
attempts to retrieve it fail.

Your function works again (once) when the application is reinitialized
because the event handlers are rebuilt, restoring the argument that
was removed. Using the duplicate() function to create your "args"
variable works because you are then working with a copy of the
arguments structure, and not changing the internal property.

I must admit that I am somewhat curious as to why you are deleting
arguments in the first place, as the intention is for them to be
immutable properties of an event handler, demonstrated by the fact
that there are no mutator methods for arguments in the event API.

Also note that you don't need to return anything from a message
listener function -- I would recommend using "void" if you wish to
specify a returntype, and removing the cfreturn tag (or at least
changing it to return nothing, i.e. <cfreturn />).

HTH,

--
Ezra Parker


On Sun, Dec 13, 2009 at 9:10 AM, Jonathan Logue <[email protected]> wrote:
> Right - the error occurs on StructFind(), but does not error if I
> remove the StructDelete() call. The key is present in the struct when
> I dump and abort either before or after the structFind call... it just
> has to happen before the structDelete call.
>
> On Dec 13, 2:36 am, Chris Blackwell <[email protected]> wrote:
>> Hi Jonathan,
>>
>> StructDelete() doesn't throw an error if key is not found in the struct, the
>> error you are seeing is from StructFind().
>> What do you see if you cfdump args and then abort before structfind?
>>
>> Chris
>>
>> 2009/12/13 Jonathan Logue <[email protected]>
>>
>>
>>
>> > I decided to take a look at Gesture this evening and ran into an
>> > issue. I have a controller method that was working in MG Unity on both
>> > CF7 and CF9 and busts using Gesture. I am using ColdSpring 1.2.
>>
>> > I have tried a lot of different things leading to completely gutting
>> > my method to what you see below.
>>
>> > <cffunction name="getObjectsByClass" returnType="WEB-
>> > INF.cftags.component">
>> >        <cfargument name="event" type="WEB-INF.cftags.component">
>>
>> >        <cfset var args = arguments.event.getAllArguments() />
>> >        <cfset var class = structFind(args,'class') />
>> >        <cfset structDelete(args,'class') />
>> >        <cfabort />
>>
>> >        <cfreturn arguments.event />
>> > </cffunction>
>>
>> > Error: coldfusion.runtime.IllegalStructAccessException: Cannot find
>> > class key in structure. at coldfusion.runtime.
>> > Struct.StructFind(Struct.java:278) at coldfusion.runtime.
>>
>> > The code above works on the same request that I "init" the application
>> > but errors on any subsequent request. It works if I remove the
>> > structDelete() call. It also works if I use the duplicate() method to
>> > copy the arguments structure... I could just implement this, but I
>> > would like to understand what is going on. It occurred to me that
>> > "class" could be reserved, so I modified the variable name and
>> > continued to receive the error. I also reproduced this behavior in the
>> > sample hello world app. I have run several experiments independent of
>> > the framework and have not been able to reproduce which is why I am
>> > posting here in the MG group.
>>
>> > This works in a simple cfm page:
>>
>> > <cfset arguments = {class='someclass',returnVariable='myreturnvar'} />
>> > <cfset args = arguments />
>> > <cfset _class = structFind(args,'class') />
>> > <cfset structDelete(args,'class') />
>> > <cfdump var="#args#">
>> > <cfdump var="#_class#">
>>
>> > Any insight is appreciated!
>>
>> > --
>> > Model-Glue Sites:
>> > Home Page:http://www.model-glue.com
>> > Documentation:http://docs.model-glue.com
>> > Bug Tracker:http://bugs.model-glue.com
>> > Blog:http://www.model-glue.com/blog
>>
>> > You received this message because you are subscribed to the Google
>> > Groups "model-glue" group.
>> > To post to this group, send email to [email protected]
>> > To unsubscribe from this group, send email to
>> > [email protected]<model-glue%2bunsubscr...@googlegrou­ps.com>
>> > For more options, visit this group at
>> >http://groups.google.com/group/model-glue?hl=en- Hide quoted text -
>>
>> - Show quoted text -
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
>

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to