我一直在努力解决这个错误,似乎找不到解决方案。我正在使用FW / 1 - Framework One 2.2,ACF 9,MS SQL 2008,jQyery 1.10.2。 我试图通过AJAX发布一个简单的表单,我收到此错误消息。非常感谢任何见解!
详细信息:如果将组件名称指定为此参数的类型,则可能无法找到组件的定义文件或无法访问该组件的定义文件。
消息:传递给setTaskLog函数的TASKLOG参数不是string类型。
表格
<form id="taskActivityForm">
<input type="text" name="id" value="">
<input type="text" id="taskID" name="taskID" value="">
<div class="modal-body">
<textarea name="taskLog" id="taskLog" class="input-block-level" rows="5"> </textarea>
</div>
</form>
的jQuery
$.ajax({
type: "POST",
url: "/ccc/tasklog/save",
dataType: "json",
data: $("#taskActivityForm").serialize(),
success: function(returnData){
console.log(returnData);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
}
});
模型TaskLog.cfc
<cfcomponent displayname="TaskLog" output="false">
<cfset variables.id = "" />
<cfset variables.taskID = "" />
<cfset variables.taskLog = "" />
<cfset variables.postedBy = "" />
<cfset variables.postedById = "" />
<cffunction name="init" access="public" output="false" returntype="TaskLog">
<cfreturn this />
</cffunction>
<cffunction name="setId" access="public" output="false">
<cfargument name="id" type="string" required="true" />
<cfset variables.id = arguments.id />
</cffunction>
<cffunction name="getId" access="public" returntype="string" output="false">
<cfreturn variables.id />
</cffunction>
<cffunction name="setTaskID" access="public" output="false">
<cfargument name="taskID" type="string" required="true" />
<cfset variables.taskID = arguments.taskID />
</cffunction>
<cffunction name="getTaskID" access="public" returntype="string" output="false">
<cfreturn variables.taskID />
</cffunction>
<cffunction name="setTaskLog" access="public" output="false">
<cfargument name="taskLog" type="string" required="true" />
<cfset variables.taskLog = arguments.taskLog />
</cffunction>
<cffunction name="getTaskLog" access="public" returntype="string" output="false">
<cfreturn variables.taskLog />
</cffunction>
<cffunction name="setPostedBy" access="public" output="false">
<cfargument name="postedBy" type="string" required="true" />
<cfset variables.postedBy = arguments.postedBy />
</cffunction>
<cffunction name="getPostedBy" access="public" returntype="string" output="false">
<cfreturn variables.postedBy />
</cffunction>
<cffunction name="setPostedById" access="public" output="false">
<cfargument name="postedById" type="string" required="true" />
<cfset variables.postedById = arguments.postedById />
</cffunction>
<cffunction name="getPostedById" access="public" returntype="string" output="false">
<cfreturn variables.postedById />
</cffunction>
</cfcomponent>
控制器TaskLog.cfc
<cfcomponent displayname="TaskLog" output="false">
<cfset variables.fw = "" />
<cffunction name="init" access="public" output="false" returntype="any">
<cfargument name="fw">
<cfset variables.fw = arguments.fw>
<cfreturn this>
</cffunction>
<cffunction name="setTaskLogService" access="public" output="false" returntype="void">
<cfargument name="taskLogService" type="any" required="true" />
<cfset variables.taskLogService = arguments.taskLogService />
</cffunction>
<cffunction name="getTaskLogService" access="public" output="false" returntype="any">
<cfreturn variables.taskLogService />
</cffunction>
<cffunction name="save" access="public" output="false" returntype="void">
<cfargument name="rc" type="struct" required="true">
<cfset var taskLogService = getTaskLogService() />
<cfset rc.tasklog = taskLogService.get(argumentCollection=rc) />
<!--- update the tasklog object with the data entered --->
<cfset variables.fw.populate( cfc=rc.tasklog, trim=true )>
<!--- call save function in services --->
<cfset saveTaskLog= taskLogService.save(rc)>
<cfif saveTaskLog.success>
<cfset rc.id = saveTaskLog.id>
</cfif>
<cfset variables.fw.renderData("json", rc)>
</cffunction>
<cffunction name="list" access="public" output="false" returntype="void">
<cfargument name="rc" type="struct" required="true">
<cfset rc.tasks = gettaskLogService().list(rc=rc)>
</cffunction>
</cfcomponent>
服务tasklog.cfc
我在get函数的new()调用之前做了一个cfdump。 “测试”对我来说似乎是一个字符串。
<cfcomponent displayname="TaskLogService" output="false">
<cfset variables.taskLogs = structNew()>
<cffunction name="init" access="public" output="false" returntype="any">
<cfreturn this>
</cffunction>
<cffunction name="new" access="public" output="false" returntype="any">
<cfreturn createObject("component", "ccc.model.taskLog").init()>
</cffunction>
<cffunction name="get" access="public" output="false" returntype="any">
<cfargument name="id" type="string" required="false" default="">
<cfset var result = "">
<cfif arguments.id neq "">
<cfquery datasource="#application.dsn#" name="qTaskLogByID">
select * from taskLogs where id =<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#">
</cfquery>
</cfif>
<cfif len(id) AND qTaskLogByID.RecordCount>
<cfset taskLog = new()>
<cfset taskLog.setId(qTaskLogByID.id)>
<cfset taskLog.settaskId(qTaskLogByID.taskId)>
<cfset taskLog.settaskLog(qTaskLogByID.taskLog)>
<cfset taskLog.setpostedBy(qTaskLogByID.postedBy)>
<cfset taskLog.setpostedById(qTaskLogByID.postedById)>
<cfset result = taskLog>
<cfelse>
<cfset result = new()>
</cfif>
<cfreturn result>
</cffunction>
<cffunction name="save" access="public" output="false" returntype="any" returnformat="JSON">
<cfargument name="rc" type="any" required="true">
<cfset var local = structNew()>
<cfif rc.id NEQ "">
<cfquery datasource="#application.dsn#">
update statement…
</cfquery>
<cfelse>
<cfquery datasource="#application.dsn#" name="qTaskLogInsert">
insert into taskLogs (taskId,taskLog,postedBy,postedById)
values (
<cfqueryparam cfsqltype="cf_sql_integer" value="#rc.task.getTaskId()#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#rc.task.getTaskLog()#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#rc.task.getPostedBy()#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#rc.task.getPostedById()#">
)
select @@IDENTITY as newID
</cfquery>
</cfif>
<cfset local.response['id'] = qTaskLogInsert.newID>
<cfset local.response['success'] = true>
<cfreturn local.response>
</cffunction>
</cfcomponent>
提前感谢您的见解!
答案 0 :(得分:3)
您正在使用组件实例覆盖控制器中的rc.taskLog,该组件实例会清除您从表单提交的字符串。
<cfset rc.tasklog = taskLogService.get(argumentCollection=rc) />
为组件实例选择与表单字段不同的变量名称。