Cannot convert the value of type class coldfusion.runtime.TemplateProxy to a boolean

1,014 views
Skip to first unread message

Sam

unread,
Mar 22, 2011, 9:59:12 AM3/22/11
to ColdFusion on Wheels
Hi All,
I'm not really a newbee anymore but this simple code doesn't be
working for some reason. I'm getting the following when I run the
create function. It's the conditional <cfif project.create()> that
giving the problem. I'm validating on the model, <cfset
validatesPresenceOf("projectTitle")>.


Cannot convert the value of type class
coldfusion.runtime.TemplateProxy to a boolean

The error occurred in /Applications/ColdFusion9/wwwroot/slotc-
nonprofits/controllers/Projects.cfc: line 46
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/wheels/
global/cfml.cfm: line 174
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/wheels/
controller/processing.cfm: line 85
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/wheels/
controller/processing.cfm: line 60
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/wheels/
dispatch/request.cfm: line 285
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/wheels/
index.cfm: line 1
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/
index.cfm: line 1
Called from /Applications/ColdFusion9/wwwroot/slotc-nonprofits/wheels/
events/onrequest.cfm: line 1

44 : <cfset project = model("project").create(modParams)>
45 :
46 : <cfif project.create()>
47 : <cfset redirectTo(action="index")>
48 : <cfelse>

Here's the cfwheels code:

<cffunction name="create">
<cfset modParams = structNew()><!---params contains a key named
"id". This is needed for the cfselect tag to produce the dependent
select box effect. I want to rename this key to categoryId so as not
to confuse CFWheels.--->
<cfset modParams.categoryTypeId = #params.categoryTypeID#>
<cfset modParams.categoryId = #params.id#>
<cfset modParams.projectTitle = #params.projectTitle#>
<cfset modParams.description = #params.description#>
<cfset modParams.nonProfitId = #session.currentUser.id#>
<cfset modParams.telecommute = #params.telecommute#>
<cfset project = model("project").create(modParams)>

<cfif project.create()>
<cfset redirectTo(action="index")>
<cfelse>
<cfset renderPage(action="add")>
</cfif>

</cffunction>

Chris Peters

unread,
Mar 22, 2011, 10:10:56 AM3/22/11
to cfwh...@googlegroups.com
create() returns an instance of the object, not a boolean. save() will return a boolean, so I recommend doing something like this:

<cfset project = model("project").new(params.project)>
<cfif project.save()>

</cfif>


--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.


Neokoenig

unread,
Mar 22, 2011, 10:11:46 AM3/22/11
to cfwh...@googlegroups.com, Sam
Two things:
What do you get when you do:


<cfset project = model("project").create(modParams)>
<cfdump var="#project#">

?

Is it returning a model, or a boolean?

What happens if you do:


<cfset project = model("project").create(modParams)>
<cfif project.hasErrors()>
<cfset renderPage(action="add")>
<cfelse> 
<cfset redirectTo(action="index")>
</cfif>

Second thing would be - would it not be simpler to just alter the params struct, or duplicate it, then delete the key you don't want?
i.e
<cfset modParams=params>
<cfset modParams.nonProfitId = session.currentUser.id> <!--- NB: you don't need the hash signs--->
<cfset modParams.categoryId=params.id>
<cfset structdelete(params, "id")>

Or forget about the modParams struct, and do
<cfset params.categoryId=params.id>
<cfset params.nonProfitId = session.currentUser.id>
<cfset structdelete(params, "id")>

Per Djurner

unread,
Mar 22, 2011, 10:11:56 AM3/22/11
to cfwh...@googlegroups.com
The create() method does not return a boolean value, it returns the object that was created (if it was created successfully).

Sam Singer

unread,
Mar 22, 2011, 10:20:40 AM3/22/11
to cfwh...@googlegroups.com
Thanks to all of the responders.  You guys are so fast!  I didn't realize that create() would not return a boolean, though it was dumping an object.  Problem solved!
Roll on Wheels!!!
--
Sam Singer
Reply all
Reply to author
Forward
0 new messages