Model-Glue Tip: Watch those event values!

So I thought I’d blog about a problem I’ve run into a few times now. Hopefully this will help people avoid the mistake I’ve made.

I was working on a user editor and as part of the process, I get the groups value from the event scope.

<cfset var groups = arguments.event.getValue("groups")>

Whenever I passed this value to my code to update the groups for a user, I kept getting an empty value groups. The first thing I checked was to see if I had named the form field right. That was ok. I then used this code to debug my event:

<cfdump var="#arguments.event.getAllValues()#">

This didn’t show anything different. The groups value was definitely blank.

I then remembered why it was blank. I was slowly rolling the “Groups” concept into the site. As part of my updates, I was adding the user’s current groups to the event state in my onRequestStart controller method. Basically, I was setting groups to blank and overriding my form value.

This is the second time I’ve done this and I think what I’m going to do is start writing down (in the project notes, core source code, wherever), a list of all values set by onRequestStart. Just to ensure I “stay out of the way” of those values.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments