2

I’m been struggling with this error and can’t seem to find a solution for it. I’m using FW/1 - Framework One 2.2, ACF 9, MS SQL 2008, jQyery 1.10.2. I’m trying to post a simple form via AJAX and I’m getting this error message. Any insight is much appreciated!

Detail: If the component name is specified as a type of this argument, it is possible that either a definition file for the component cannot be found or is not accessible.

Message: The TASKLOG argument passed to the setTaskLog function is not of type string. enter image description here

Form

<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

enter image description here

$.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);
    }
  });

Model 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>

Controller 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>

Service tasklog.cfc

I did a cfdump right before the new() call in the get function. "testing" appears to be a string to me. enter image description here

<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>

Thank you in advance for your insights!

user752746
  • 617
  • 9
  • 31
  • 1
    The title of your question is misleading as it is the error "detail" and not the error "message". The detail in this case has nothing to do with your actual error and is an assumption of what might be going on by the CF engine. Since you aren't specifying a component name for your argument, the detail doesn't apply to you. – Brad Wood Jul 18 '14 at 20:26
  • I see your point, let me see if I can change that. – user752746 Jul 18 '14 at 21:08
  • I submitted a title edit, but it told me it had to go through peer review. I'm not a S/O god yet, so I don't have those powers :) – Brad Wood Jul 18 '14 at 22:52
  • My insight is that "simple" and "posting via ajax" is an oxymoron. – Dan Bracuk Jul 18 '14 at 23:27

1 Answers1

3

You're overwriting rc.taskLog in your controller with a component instance which wipes out the string that you submitted from the form.

 <cfset rc.tasklog = taskLogService.get(argumentCollection=rc) />

Choose a different variable name for your component instance than your form field.

Brad Wood
  • 3,863
  • 16
  • 23