cfprogressbar cfc bind runs correctly but need to pass parameter

New Here ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

 

Currently, I am Using ColdFusion 2018, and trying to add a progress bar on an API call. So I created a cfc function to fetch this API details. For this I will call a "getStatus()" function through bind params. And able to load the cfprogress bar successfully. The problem is that I need to pass an en extra parameter to this getstatus function . Is it possible? 

 

Please see the code I used to load cfprogressbar

 

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<script type="text/javascript">

function startProgress() {
ColdFusion.ProgressBar.start("mydataProgressbar");
};


function onfinish() {
alert("Done");
};
</script>

<body>
<cfif IsDefined("Session.STATUS")>
<cfscript>
StructDelete(Session,"STATUS");
</cfscript>
</cfif>

<cfset sjsondata = '{"name":"Jibin","id":"1234"}'>
<!--- For code simplicity, formatting is minimal. --->
<cfform name="kitform">
<p>To make our service better and to benefit from our special offers,
take a moment to give us your email address and send us a comment.</p>
<p>Name:
&nbsp;<cfinput type="text" name="name"> </p>
<p>E-mail:
&nbsp;<cfinput type="text" name="email"> </p>
<p>Comment:
&nbsp;<cftextarea name="cmnt"/></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<cfoutput>
<cfinput type="hidden" name="jsondata" value="#sjsondata#">
</cfoutput>
<cfinput type="button" name="bttn1" value="Send Comment"
onClick=startProgress()></p>
<!--- The progressbar control --->
<cfinput type="button" name="bttn2" value="Send Comment 2"
onClick=startProgress2()></p>
<div style="padding-left:3px" >


<cfprogressbar name="mydataProgressbar"
bind="cfc:progressbar.getstatus({jsondata})"
interval="1700"
width="200"
oncomplete="onfinish"/>


</cfform>
</body>
</html>

 

progressbar.cfc

<cfcomponent name="progressbar">
<cffunction name="getstatus" access="remote">
<cfargument name="jsonData" type="string" required="false">

<cfset str = StructNew()>
<cfset str.message = "Saving Data">
<cfif NOT IsDefined("session.STATUS")>
<cfset session.STATUS = 0.1>
<cfscript>
Sleep(200);
</cfscript>
<cfelseif session.STATUS LT 0.9>
<cfset session.STATUS=session.STATUS + .1>
<cfscript>
Sleep(200);
</cfscript>
<cfelse>
<cfset str.message = "Done...">
<cfset session.STATUS="1.0">
</cfif>
<cfset str.status = session.STATUS>
<cfreturn str>
</cffunction>

</cfcomponent>

 

Question 1: Can i  pass a parameter to cfprogressbar getstatus() function. Please confirm?

 

Question 2: Do any one know any other method to do this process in progressbar. 

I appreciate for the advance help.

 

Views

107

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

According to the help page for cfprogressbar:

 

"If you use a bind expression, the called function takes no parameters, and must return a structure with two values"

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Thank you for your kind full support.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Right, I would have asked: "what is it that you want to pass to the getstatus function?" And why are you passing the jsondata as you are? If you're not aware, that CFC you have is nearly identical to what is in the docs, and the docs don't show it taking any function. Why are you wanting to modify that? Sometimes "why" is more important to answer first than "how". 🙂

 

And you ask at the end for "any other method to do this process in progressbar". What "process" do you mean? If you state it in words it may help versus us trying to sort it out from the code. Just trying to help.

 

Also, have you gotten it (the progressbar) working at all, as a start (just using the example in the docs)? If so, you could try to build on it, of course. But having a basic working example first is often key.

 

More than that, do beware that the progressbar may well be one of the "UI" tags that are deprecated since CF2016 and whose underlying "yui library" folder has been removed from CF2018. You can see more about that (and how to add it back, if you must, at the bottom) here: https://helpx.adobe.com/coldfusion/deprecated-features.html


/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

Thank you for your kindful information. 

This is the sample code that is created to test the cfprogressbar. Really I need to pass any parameter to the getstatus function.

 

The actual function is 

<cffunction name="getstatus" access="remote">
<cfset str = StructNew()>
<cfset str.message = "Saving Data">
<cfif NOT IsDefined("session.STATUS")>
<cfset session.STATUS = 0.0>
<cfset str.message = "Started...">
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelseif val(session.STATUS) eq 0.1>
<cfset str.message = getCdKSalesOrder()>
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelseif val(session.STATUS) eq 0.2>
<cfset str.message = getCdKSalesOrder2()>
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelseif session.STATUS eq 0.3>
<cfset str.message = getCdKSalesOrder3()>
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelseif session.STATUS eq 0.4>
<cfset str.message = getCdKSalesOrder4()>
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelseif session.STATUS eq 0.5>
<cfset str.message = getCdKSalesOrder5()>
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelseif session.STATUS LT 0.9>
<cfset session.STATUS = numberFormat( val(session.STATUS) + 0.1,'9.9')>
<cfelse>
<cfset str.message = "Done...">
<cfset session.STATUS = "1.0">
</cfif>

<cfset str.status = session.STATUS>
<cfreturn str>
</cffunction>

 

In the above getstatus function, I need to do five additional tasks (mainly 5 API calls). For this I need to call the 5 additional functions based on the status field. For doing this function I need to pass at least one parameter to accept in the getstatus function. That is the reason I asked for this. If you have any suggestions please let me know.  Once again thanks a lot for the kindful reply

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 16, 2020 Sep 16, 2020

Copy link to clipboard

Copied

LATEST
<cfset sjsondata = '{"name":"Jibin","id":"1234"}'>
...
<!--- Will be available to function in CFC --->
<cfset session.jsonData = sjsondata >

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines