Search code examples
coldfusioncoldfusion-9

Test if a variable is a component or Boolean


I am trying to figure out how I can test if the function of a component has returned a component or Boolean false.

For example a component's find method like

<cfset hotel = oHotel.findById(1200) />
<cfif  hotel >
 ...
</cfif>

If a hotel is found then a component is returned, otherwise false. Is it generally OK to write such code, or should I write to the cfif another way?


Solution

  • Alternatively, IsSimpleValue() can be used to determine if the variable is...a simple value. That is, not an array, struct, query, or component.

    Returns
    True, if value is a string, number, Boolean, or date/time value; False, otherwise.

    <cfset hotel = oHotel.findById(1200) />
    <cfif  IsSimpleValue(hotel)>
      <!--- it is a simple value, i.e., NOT a component --->
    </cfif>