Railo News
- March 19, 2012
- CFLOOP over arrays as collections
The default looping approach one has is to either loop from 1 to the last element of an array or to use the <cfloop array=”#theArray#” index=“element”> notation. Next to the fact that the naming is misleading, both approaches have a disadvantage. So let's have a look:
<cfset aArray = ["January","February","March","April","May","June","July", "August","September","October","November","December"]> <cfset aArray[14] = "Out of bounds"> <cfloop from="1" to="#arrayLen(aArray)#" index="i"> <cfoutput>#i#: #aArray[i]#<br></cfoutput> </cfloop>
The above code loops through a regular array until the last element of the array. But of course the 13th element will cause a runtime error since there is no Element at position 13. So you would need to do something like:
<cfloop from="1" to="#arrayLen(aArray)#" index="i"> <cfif arrayIndexExists(aArray, i)> <cfoutput>#i#: #aArray[i]#<br></cfoutput> </cfif> </cfloop>
So you could use the other notation (for arrays) which looks like this:
<cfloop array="#aArray#" index="i"> <cfoutput>#i#: #aArray[i]#<br></cfoutput> </cfloop>
This of course throws an error since the introduction of this behaviour is misleading. Unfortunately the index does NOT contain the index but the element of the array. So aArray[i] above would throw an error. You would have to use this approach:
<cfset iCnt = 0> <cfloop array="#aArray#" index="sElem"> <cfoutput>#++iCnt#: #sElem#<br></cfoutput> </cfloop>
But this is ugly right? Or what happens if you have the following array:
<cfset aArray = []> <cfset aArray[2] = "February"> <cfset aArray[4] = "April"> <cfset aArray[6] = "June"> <cfset aArray[8] = "August"> <cfset aArray[10] = "October"> <cfset aArray[12] = "December"> Then the second solution wouldn't work since the position of the element is unknown. Only the first one would work with a little conditioning: <cfloop from="1" to="#arrayLen(aArray)#" index="i"> <cfif arrayIndexExists(aArray, i)> <cfoutput>#i#: #aArray[i]#<br></cfoutput> </cfif> </cfloop>
In other engines you may have to use <cfif ArrayIsDefined(aArray[i])> if possible. But why not use a very nice way of looping over arrays by using the collection loop (This, BTW, only works on Railo):
<cfset aArray = ["January","February","March","April","May","June","July", "August","September","October","November","December"]> <cfloop collection="#aArray#" item="i"> <cfoutput>#i#: #aArray[i]#<br></cfoutput> </cfloop> <br> <cfset aArray = []> <cfset aArray[2] = "February"> <cfset aArray[4] = "April"> <cfset aArray[6] = "June"> <cfset aArray[8] = "August"> <cfset aArray[10] = "October"> <cfset aArray[12] = "December"> <cfloop collection="#aArray#" item="i"> <cfoutput>#i#: #aArray[i]#<br></cfoutput> </cfloop>
The generated output is:
1: January
2: February
3: March
4: April
5: May
6: June
7: July
8: August
9: September
10: October
11: November
12: December2: February
4: April
6: June
8: August
10: October
12: DecemberSo using the collection notation in really helps you speed up coding and even respects empty indexes.
- March 12, 2012
- Configuring Railo Resources
You can configure your Railo resources by editing the railo-web.xml.cfm or railo-server.cfm file. In these files you will find an entry that looks like this:
<resource-provider arguments="case-sensitive:true;lock-timeout:1000;" class="railo.commons.io.res.type.ram.RamResourceProvider" scheme="ram"/>
The class locations could be:
- railo.commons.io.res.type.cache.CacheResourceProvider
- railo.commons.io.res.type.datasource.DatasourceResourceProvider
- railo.commons.io.res.type.file.FileResourceProvider
- railo.commons.io.res.type.ftp.FtpResourceProvider
- railo.commons.io.res.type.http.HTTPResourceProvider
- railo.commons.io.res.type.http.HTTPSResourceProvider
- railo.commons.io.res.type.ram.RamResourceProvider
- railo.commons.io.res.type.s3.S3ResourceProvider
- railo.commons.io.res.type.tar.TarResourceProvider
- railo.commons.io.res.type.tgz.TGZResourceProvider
- railo.commons.io.res.type.zip.ZipResourceProvider
For example, you can configure these resources to be case sensitive or not, allowing you to test an application that is to be deployed on a Linux machine in a Windows development environment. Simply create a mapping that points to a case-sensitive ZIP resource and test your application!
- March 10, 2012
- Nic Tunney on deploying Railo, Tomcat and Apache on Amazon EC2 Ubuntu AMI
Nic Tunney has a blog post on deploying Railo, Tomcat and Apache on Amazon EC2 Ubuntu AMI. The money quote:
There are 13 actual commands to install Apache, Railo and Tomcat. There are 7 lines of configuration to paste into two config files. It doesn't get much easier.
We agree :)
Mark Drew's personal blog
- February 29, 2012
- Railo Book Competition: The Winners!
A couple of weeks ago I run a competition to win my Railo 3 Beginner's Guide book. So now is the time to announce the winners!
In first place is Ben B. who wins a signed copy of the book for his myth "The cost for creating a cfc object is minimal and has no real cost."
In joint second place, winning an electronic copy of the book are:
Ray V. with his myth "Is there really a cookie called CFMagic?"
and
Steven R. with his myth "ColdFusion will always timeout to the value I provide in the ColdFusion Adminsitrator."In third place, winning a mention in my presentation is Brendan with his myth "cfml produced html is full of whitespace"
Congratulations to you all! I shall get the presentation updated for cf.Objective!
I have also put the code up on how I run the code and presentation on github, so you can check out the CFML Mythbusters presentation for yourself!
- September 26, 2011
- CFCamp 2011! Be there or be a Pretzel!
Munich! City of Oktober fest and Pretzels! The big soft ones with butter inside. What could be more delicious than that? I tell you what is... CFCAMP 2011 is!
That's right ladies and gentle-folks, after a three year hiatus, there is going to be a stomping and knowledge-infusing conference in Munich this year, filled to the gills with awesome presenters and me!
For a measly €90 a ticket (going up to €119 in October, so get them whilst they are fresh!), your mind can be blown by the likes of Charlie Arehart (he of the inside secrets into ColdFusion 10!), Luis Majano (he of the mobile knowledge), Gary Gilbert exposing his JQuery to the public, Bilal Soylu will also be locking down your apps, and of course Andy Allan and myself, giving it all from our presenter's pulpit.
Sure you can't miss this?!
Head over to
www.cfcamp.org/anmeldung.cfmwww.cfcamp.org/registration.cfm?ChangeLanguageTo=en to get your tickets (yep, it's in German, just use Chrome and translate it, you are a clever person right?This time in English! Don't say we don't spoil you!)
- August 22, 2011
- Checking the memory of your applications in Railo 3.3.0.026 rc
If you have ever wondered how your memory is being used in a Railo Server application, why not get the latest development release of Railo Server: 3.3.0.026 rc (you know that you can do this from the server administrator right?).
Just go to yourdomain/railo-context/admin/server.cfm and log in, then you can click on the "update" button, set the updates to "Development", update and then click the "execute button below to get the latest update.
Once you have done that, in the Railo Server Administrator screen, you will see info about your installation and scrolling down you will get a nice graphic on how your memory is being used, like the example below:
Yet another handy feature of Railo Server! Nice!