CFGroovy Demo
CFGroovy Demo
Links: CFGroovy homepage
| source for this page.
| groovy grouping demo
This demo creates an array of strings, CFDUMPs it, and then uses
various scripting languages to add new elements to the array and output
it to the page. Groovy and JavaScript are guaranteed to work, Python,
PHP, and Ruby will also run if you have Jython, Quercus, and JRuby JARs
on your classpath.
Starting Array
Run some Groovy
variables.myArray.add("Groovy is...Groovy!")
println "${variables.myArray}
"
Run some JavaScript
variables.get("myArray").add("JavaScript is lovely!")
print("" + variables.get("myArray") + "
")
Run some Python (via Jython)
variables["myArray"].append("Pythons are scary.")
## this doesn't actually work, because the Jython JSR-223 implementation
## doesn't respect the context-supplied writer, but instead always uses
## System.out. You'll see this output on the console, but it can't be
## captured for use within page rendering. If you care, yell at Jython.
print variables["myArray"]
Jython doesn't support shared output streams...
Jython needs to be added to your classpath for the Python example to work
Error running Jython code: #cfcatch.message#
#cfcatch.detail#
Run some PHP (via Quercus)
";
var_dump($variables["myArray"]);
echo "";
?>
Quercus needs to be added to your classpath for the PHP example to work
Error running PHP code: #cfcatch.message#
#cfcatch.detail#
Run some Ruby (via JRuby)
$variables["myArray"] << "Rubies are sparkly."
puts "##{$variables['myArray']}
"
JRuby needs to be added to your classpath for the Ruby example to work
Error running Ruby code: #cfcatch.message#
#cfcatch.detail#
Run move Groovy
// and some other stuff, using some other syntaxes
variables.myArray += "CF Runtime: " + server.coldfusion.productname + " " + server.coldfusion.productversion
variables.myArray << "User Agent: " + cgi.http_user_agent
println("List:")
variables.myArray.each {
println(" \"$it\"")
}
println("
")
Final Array