cfc binding with wheels (cfprogressbar example)

185 views
Skip to first unread message

retfird

unread,
Oct 1, 2012, 1:23:35 AM10/1/12
to cfwh...@googlegroups.com
Coldfusion Binding with CFWheels.  

The recommendations I found from researching was to put cfc's in the miscellaneous folder for remote calling.  The issue with that method is that controllers in misc can't use native wheels functions.

One workaround for this is to bind to urls.

Here is an example of the CFPROGRESSBAR binding to a cfwheels controller without plugins:

Controller:
/controllers/progress.cfc
Taken straight from cf9 docs and turned to cfscript.  Note the init function and return method for progress function

component extends="Wheels" {

function init() {

provides("json");  // Necessary to allow calling to ?format=json from the remote call to return JSON data

}

remote function progress() {

str = StructNew();
str.message = "Saving";
if (!IsDefined("session.status")) {
session.status = 0.1;

sleep(200);

}
else if (session.status < 0.9) {
session.status = session.status + .1;
sleep(200);
}
else {
str.message = "Done!";
session.status = 1;
}
 
str.status = session.status;
return(renderWith(data=str, layout=false));
}

}

Views:
Create an empty /views/progress/progress.cfm file so wheels doesn't complain about missing view

Now the remote call:
/miscellaneous/progress.cfm
note the bind url and expecting ?format=json

<script>
startBar = function() {
ColdFusion.ProgressBar.start("test");
}
</script>
<cfif IsDefined("Session.STATUS")> 
    <cfscript> 
        StructDelete(Session,"STATUS"); 
    </cfscript> 
</cfif>  

<cfprogressbar name="test" interval="1000"
  bind="url:/progress/progress/?format=json"
  autodisplay="true">
     

<a href="javascript:startBar()"> Start! </a>


I've never really found examples of others doing this, so I thought i'd share.

Cheers,

Andy Bellenie

unread,
Oct 1, 2012, 8:41:52 AM10/1/12
to cfwh...@googlegroups.com
If it's a controller, why isn't it in the controller's folder? Misc is for utility CFCs that exist outside of the Wheels app. 


--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/5fmDginR5psJ.
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.

retfird

unread,
Oct 1, 2012, 9:02:18 AM10/1/12
to cfwh...@googlegroups.com
It is, the first one is the controller.

The stuff in misc is just where i put the cfprogressbar to bind to the cfc/url from the controller.

Chris Peters

unread,
Oct 1, 2012, 9:19:36 AM10/1/12
to cfwh...@googlegroups.com
Binding anything from built-in ColdFusion does not play nicely with Wheels. Also, anytime you use anything interface-related from CF tags (<cfmap>, <cfvideo>, etc.), it includes an awful number of JavaScript and CSS files in the <head>. It is disgusting.

As an alternative, I recommend finding a jQuery alternative that behaves like an adult and using it instead. You'll find it to work out better in the long run.

To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/yLVoN7ZuXc8J.

retfird

unread,
Oct 1, 2012, 9:30:13 AM10/1/12
to cfwh...@googlegroups.com
I can't argue with that, but i've been binding cfgrid's with wheels urls for a while, and I haven't encountered any issues so far.

using the cf tags is advantageous when using extjs throughout the project, since you can theme it using extjs css files.  I found it a nice way to skin projects without the need to work exclusively with extjs code.
Reply all
Reply to author
Forward
0 new messages