Velocimacro - Generate a HTML Select box and its Options
A quick and simple Velocimacro to generate HTML Select boxes and its Options; automatically selects the correct option based on the value given. You can place this #macro anywhere in your Velocity templates but I used my global VM_global_library.vm file. Code ``` #macro( generateSelectBox $name $options $value ) #foreach ( $option in $options ) #set( $selected = "" ) #if ( $option == $value ) #set( $selected = "selected='true'" ) #end $option #end #end ``` Example Usage ``` #generateSelectBox( "enabled" ["Y","N"] $form.enabled ) ``` The resulting HTML: ``` Y N ``` Addendum 11th November 2005 : Thanks to MATT for pointing out the FreeMarker template engine as a promising replacement for Velocity. ;)
Related Posts
Hadoop: Processing ZIP files in Map/Reduce
Updated ZipFileInputFormat framework for processing thousands of ZIP files in Hadoop with failure tolerance and comprehensive examples
Consuming Twitter streams from Java
Build a Java utility class to consume Twitter Streaming API data for offline analysis in Hadoop with automatic file segmentation
Reading ZIP files from Hadoop Map/Reduce
Custom utility classes to extract and parse ZIP file contents in Hadoop MapReduce jobs using ZipFileInputFormat and ZipFileRecordReader