使用参数创建cfthread并检查cfprogressbar

时间:2017-09-15 17:21:06

标签: javascript ajax coldfusion cfml

请你帮我解决ColdFusion中交互式线程控制的问题。我无法理解ColdFusion中的回调,缺少来自asp.net的新手。

我有一个cfform这样的页面:

<cfform method="get">
<cfif isDefined("URL.s1")>
<cfselect name="s1" bind="cfc:chart.getS1()" bindonload="true" selected=#URL.s1#/>
<cfelse>
<cfselect name="s1" bind="cfc:chart.getS1()" bindonload="true"/>
</cfif>
<cfif isDefined("URL.s2")>
<cfselect name="s2" bind="cfc:chart.getS2({s1})" selected=#URL.s2#/>
<cfelse>
<cfselect name="s2" bind="cfc:chart.getS2({s1})"/>
</cfif>

<cfif isDefined("URL.m")>
<cfselect name="m">
<cfoutput>
<cfloop from="1" to="6" index="Month">
<option value="#Month#" <cfif URL.m EQ Month>selected="selected"</cfif>><cfoutput>#Month# Month<cfif Month GT 1>s</cfif></cfoutput></option>
</cfloop>
</cfoutput>
<option value="12" <cfif URL.m EQ 12>selected="selected"</cfif>>12 Months</option>
<option value="24" <cfif URL.m EQ 24>selected="selected"</cfif>>24 Months</option>
</cfselect>
<cfelse>
<cfselect name="m">
<cfoutput>
<cfloop from="1" to="6" index="Month">
<option value="#Month#" <cfif Month EQ 2>selected="selected"</cfif>>#Month# Month<cfif Month GT 1>s</cfif></option>
</cfloop>
</cfoutput>
<option value="12">12 Months</option>
<option value="24">24 Months</option>
</cfselect>
</cfif>

<input type="submit" value="Show">
<cfif isUserInRole("admin")>
<input type="submit" name="u" value="Update">
<input type="submit" name="r" value="Re-run">
</cfif>
</cfform>

<!--- Here comes the "event handlers" for the last two buttons --->
<cfif isUserInRole("admin") AND isDefined("URL.s1") AND isDefined("URL.s2") AND isDefined("URL.u")>
<cfsetting requesttimeout="0">
<cfset qSymbols=chart.updatePair(s1, s2)>
</cfif>

<cfif isUserInRole("admin") AND isDefined("URL.s1") AND isDefined("URL.s2") AND isDefined("URL.r")>
<cfsetting requesttimeout="0">
<cfset qSymbols=chart.rerunPair(s1, s2)>
</cfif>

<!--- Then the output results in a table --->
...

代码隐藏的cfc文件的某些部分:

<cffunction name="chartUpdate" output="false" access="remote">
    <cfargument name="s1" required="true" type="string" default="">
    <cfargument name="s2" required="true" type="string" default="">
    <cftry>
    <cfstoredproc procedure="chart_update" returncode="false">
        <cfprocparam value="#s1#" cfsqltype="cf_sql_varchar" maxlength="16" type="In">
        <cfprocparam value="#s2#" cfsqltype="cf_sql_varchar" maxlength="16" type="In">
        <cfprocresult name="theResponse">
    </cfstoredproc>
    <cfcatch type="any">
        <cflog file="News_DBerror" text="Message = #cfcatch.message# Detail= #cfcatch.detail#">
    </cfcatch>
    </cftry>
</cffunction>

<cffunction name="updatePair" output="false" access="remote">
    <cfargument name="s1" required="true" type="string" default="">
    <cfargument name="s2" required="true" type="string" default="">
    <cfscript>
    ...routine...
    </cfscript>
</cffunction>

<cffunction name="rerunPair" output="false" access="remote">
    <cfargument name="s1" required="true" type="string" default="">
    <cfargument name="s2" required="true" type="string" default="">
    <cfscript>
    try
    {
        chartUpdate(s1, s2);
    }
    catch (Any ex)
    {
        WriteLog(type="Error", file="News", text="[#ex.type#] #ex.message#");
    }
    </cfscript>
</cffunction>

它可以正常工作。某些DB存储过程需要大约20-30秒才能运行,因此它们适合HTTP超时,而浏览器会指示等待服务器响应,最后页面重新加载,并在后面的表和数据库中更新结果。适合我,但对现代用户体验不利。

我想点击cfprogressbarUpdate按钮添加Re-run并隐藏cfform中的所有按钮(Show,{{1进程运行时。}和Update)最后页面应该自动重新加载,隐藏Re-run,显示按钮控件和新结果。 (也许以cfprogressbar ajax的方式,我对这些细节没有经验。)

我尝试cfdiv/cflayout做了什么。

在页面顶部添加了cfprogressbar。 添加了一些javascript函数(有些函数无法正常工作,暂时注释掉,无关紧要):

<cfset session.status = 0>

我替换了<script type="text/javascript"> function initProgressBar() { //document.getElementById('doCFCbar').style.display = 'none'; ColdFusion.ProgressBar.show('cfcBar'); ColdFusion.ProgressBar.start('cfcBar'); } function finProgressBar() { //ColdFusion.ProgressBar.hide('cfcBar'); //document.getElementById('doCFCbar').style.display = 'block'; } </script> 按钮进行测试:

Rerun

这不像我后面提到的那样有用!我无法用参数调用任何<!---<input type="submit" name="r" value="Rerun">---> <cfinput type="button" name="doCFCbar" value="Rerun" onclick="initProgressBar()"> <cfprogressbar name="cfcBar" bind="cfc:chart.rerunProgress(URL.s1,URL.s2)" interval="1000" width="200" oncomplete="finProgressBar()">

以下是问题:如何在ColdFusion中实现我的想法?我不理解bind="cfc:function(URL.s1,URL.s2)"页面上的组件与cfm文件中的功能之间的交互式回调桥梁。

如何通过单击按钮创建线程,传递参数并检查线程状态?

我根据Adam Cameron的defer()函数from herecfc文件添加了一些函数,以cfthread的身份运行并检查状态。

cfc

注意:在ColdFusion2016 / SQL Server 2016上运行

UPD:好的,如果没有线程(我只是尝试了它们,线程可能不是最终的或任何好的解决方案,只是我看到获取当前进程状态的方式(运行或完成) )具有中止它的能力),

在这种情况下,在客户端页面和cfc之间建立桥梁的最佳方法是什么?特别是一般而言。

(asp.net中的解决方案基于内置回调引擎,因此为开发人员传递参数或'事件'是完全透明的。)

我是否应该为ColdFusion中的每种类型的组件手动执行此操作? 或者在下一个ColdFusion版本中是否有任何方法或将是任何内置引擎,如果我正确地了解情况,不是吗?

0 个答案:

没有答案