Is there a way in ColdFusion (or Railo for that matter) to begin sending the client the page as it processes it?
Simple: use the cfflush tag:
<cfoutput query="myQuery">
#myQuery.myData#
<cfflush>
</cfoutput>
http://www.cfquickdocs.com/cf9/?getDoc=cfflush#cfflush
Related
Anyone having issues with the cfflush tag in ColdFusion 11? We have a routine that updates a live record count as it is processing a loop. In ColdFusion 10, this works fine. In ColdFusion 11, it waits until the end of the loop to update the screen. Not really what we expected.
Edited to add code as requested...
<script language="javascript">
addOutputLine('<br /><span id="insertCount">Records Inserted: 0</span>')
</script>
<cfset insertCount = 0>
<cfset updateCountAfter = 1>
<cfif qry.recordcount gt 5000>
<cfset updateCountAfter = 10>
</cfif>
<cfoutput query="qry" startrow="#DATASTART#">
<!---do some stuff here that is not important to this issue--->
<cfset insertCount = insertCount + 1>
<cfif updateCountAfter gt 1>
<cfif insertCount mod updateCountAfter eq 0>
<script language="javascript">document.getElementById('insertCount').innerHTML = 'Records Inserted: #insertCount#';</script>
</cfif>
<cfelse>
<script language="javascript">document.getElementById('insertCount').innerHTML = 'Records Inserted: #insertCount#';</script>
</cfif>
<cfflush>
</cfoutput>
Promoted from the comments
There is a configuration setting that is necessary for the <cfflush> tag to work properly with the web server. On the Configuring web servers in Windows documentation page, under the Configure IIS for ColdFusion in Windows section, among other things it states:
To disable webserver buffer, change the is_buffer_enable [sic] to false in the cfroot\config\wsconfig\1\isapi_redirect.properties file. Disable webserver buffer if you want cfflush to work over an IIS connector. If your application does not use cfflush, set it to true for increase in the performance.
Note that there is a typo in the Adobe documentation that I referenced above. It should state iis_buffer_enable, not is_buffer_enable (missing an 'i'). Thanks to KrunchMuffin for pointing that out.
You will need to restart IIS for this change to take affect.
I'm not sure what the performance ramifications are of disabling this setting. You will need to do some load testing for your particular environment to see.
I have a URL which when run in the browser, displays JSON data, since I am new to coldfusion, I am wondering, what would be a good way to
grab the data from the web browser? Later on I will be storing the individial JSON data into MySQL database, but I need to figure out step 1
which is grabbing the data.
Please advise.
Thanks
You'll want to do a cfhttp request to load the external content.
Then you can use deserializeJSON to convert the JSON object into the appropriate cfml struct.
See the example Adobe gives in the deserializeJSON documentation.
Here is quick example:
<!--- Set the URL address. --->
<cfset urlAddress="http://ip.jsontest.com/">
<!--- Generate http request from cf --->
<cfhttp url="#urlAddress#" method="GET" resolveurl="Yes" throwOnError="Yes"/>
<!--- handle the response from the server --->
<cfoutput>
This is just a string:<br />
#CFHTTP.FileContent#<br />
</cfoutput>
<cfset cfData=DeserializeJSON(CFHTTP.FileContent)>
This is object:<br />
<cfdump var="#cfData#">
Now you can do something like this:<br />
<cfoutput>#cfData.ip#</cfoutput>
Execute this source here http://cflive.net/
Does anyone know if the new websockets feature in CF10 can be used cross domain and cross server? And does anyone know or have some sample code to do this?
I have a simple live help chat working on my app but I want to apply it to other sites and have one central admin chat area where the support agents will interact with users cross domain.
As far as I know they do not. You can, however, use a <cfhttp> to call a file on the other site that will publish the message. Here is I accomplished this.
Create a file called socketPublisher.cfm and save it in a directory that does not require a login access a file.
socketPublisher.cfm
<cfparam name="Request.Attributes.msgType" default="newJob">
<cfparam name="Request.Attributes.channel" default="notify">
<cfparam name="Request.Attributes.Type" default="">
<cfoutput>
<cfswitch expression="#Request.Attributes.Type#">
<cfcase value="yourType">
<cfscript>
WSPublish('chat',{message: '', msgType: '#Request.Attributes.msgType#'});
</cfscript>
</cfcase>
<cfdefaultcase>
<cfscript>
WSPublish('#Request.Attributes.channel#',{message: '', msgType: '#Request.Attributes.msgType#'});
</cfscript>
</cfdefaultcase>
</cfswitch>
</cfoutput>
Then in you action page on the other site, you will need to make your http request to that file.
actionPage.cfm
<cfhttp method="Post" url="#socketURL#/_scripts/socketPublisher.cfm">
<cfhttpparam type="URL" name="msgType" value="pendingFiles">
</cfhttp>
That should do it.
There is also a know issue with CF10 WSPublish that it will change the CGI scope cause error when trying to do a redirect from an action page. I am using this as a workaround for that issue until I can find a better solution.
Is there a way to redirect a user to a new window by using CFLocation? As far as I know you cannot use target=_blank in CFLocation. Is there another way to do it?
This is my code:
<cfif cgi.PATH_INFO eq "/procedure-page.cfm">
<cflocation url="http://www.example.com/example/example.cfm?id=XXXXXX&contactid=#returnStruct.contactID#&doctorid=#officeLocation#" addtoken="no" >
<cfelse>
<cflocation url="http://www.example.com/example/example.cfm?id=#example#&contactid=#returnStruct.contactID#&doctorid=#officeLocation#" addtoken="no" >
</cfif>
<cflocation> performs a client-side redirect, but it's initiated on the server side (it sends a request with a redirect in the header), so it can't know anything about "tabs" which are a browser thing. CF doesn't know anything about what's going on in the browser.
To do the sort of thing you want to do on the client site, you need to do the browser stuff with Javascript.
This is probably not the cleanest way, but it should work.
<cfoutput>
<cfif cgi.PATH_INFO eq "/procedure-page.cfm">
<script type="text/javascript">
window.open("http://www.example.com/example/example.cfm?id=XXXXXX&contactid=#returnStruct.contactID#&doctorid=#officeLocation#", '_blank');
</script>
<cfelse>
<script type="text/javascript">
window.open("http://www.example.com/example/example.cfm?id=#example#&contactid=#returnStruct.contactID#&doctorid=#officeLocation#", '_blank');
</script>
</cfif>
</cfoutput>
I believe Adam is correct in that CFLocation cannot ask the browser to open in a new window (or tab). Something that might interest you however is the CFWindow tag. See the documentation here. Note that CFWindow does not open a new browser window either, but creates a <div> to simulate a popup window. Anyway, it has several options and I thought it might be worth you taking a look at. Maybe it can handle what you need.
When a user logs in and is redirected to a secured page, the url is getting appended twice like a list. This in turn causes a 404.
(example: http://uwf.edu/something.cfm,http://uwf.edu/something.cfm)
Currently, the site has a custom login tag which I am unable to edit as I do not have control over it. (It's just a custom cf tag that allows people to login at the university.)
I have to do additional processing after this tag to verify that they are eligible to login on this particular site. Once they have been verified, they are re-directed to another page with cflocation.
<custom login tag>
<cfinvoke component="#application.path#cfc/security" method = "constructSession" returnvariable = "status">
.. params excluded..
</cfinvoke>
<cfif status eq 1>
<cflocation url="#someurl_invalid#" addtoken="no" />
<cfelse>
<cflocation url="#someurl#" addtoken="no" />
</cfif>
The custom login tag refreshed the current page already, but I obviously do not want that and thus had used the above method to re-direct. This worked in ColdFusion 8.
I read this article: http://www.bennadel.com/blog/2050-Changes-In-CFLocation-OnRequestEnd-Behavior-In-ColdFusion-9-s-Application-cfc.htm
The article gave me some insight as to what is going on...but I am unsure how to fix the issue.
Does anyone have any solutions?
Since you don't have control over the custom tag, you'll have to work around the issue instead of fixing it.
I would recommend changing the code:
<cfif status eq 1>
<cflocation url="#ListFirst(someurl_invalid)#" addtoken="no" />
<cfelse>
<cflocation url="#ListFirst(someurl)#" addtoken="no" />
</cfif>
It's not pretty but will work whether the URLs are lists or not.