Followup to last Model-Glue article - checking for the existence of a value

In my last article, I talked about what I considered to be an odd side effect of using getValue on the event object. I really should have told folks how you can check for the existence of a value without actually doing the get. In other words, if all you want to do is see if the value exists, you should do this:

<cfif arguments.event.valueExists("dharma")>

As opposed to getting it and checking if it is equal to "". Of course, if you are building a form, then you need to do both, since it is possible then the value will exist and be blank.

<cfif arguments.event.valueExists("dharma") and arguments.event.getValue("dharma") neq "">

Something to keep in mind, and while I don't like this strange behavour of getValue, I'll definitely not forget now.

p.s. The ViewState has a similar API, but it uses viewState.exists() instead.

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