Reference Manual for Gracelets - 2.0.0.SP2SourceForge.net Logo
2.11 - Tutorial : Using Converter Closures
You will usually store converters in libraries or even in controllers. But you can always write a converter right inside your view script if you want or need to. This is especially useful for prototyping, writing a quick fix or a one-time converter

If you are just referencing a converter in the variable contexts then you would simply use a value closure (i.e., converter: { someConverter }). Writing the actual implementation inside your script is demonstrated in the following example:

Toggle Line Numbers
1  
2 h.inputText(value: Value { someBean.percentValue }, converter: Converter( 
3     toString: { it + "%" }, toValue: { Integer.parseInt(it[0..-2]) } 
4 )) 
As can be seen above you can specify the toString and toValue code portions for the converter. You MUST at least specify the toValue, toString defaults to running String.valueOf() on the object. Also, null and empty strings are ignored, so you don't have to even check for null values or empty strings.