Reference Manual for Gracelets - 2.0.0.SP2SourceForge.net Logo
2.9 - Tutorial : Using VCL Closures
To use closures with what would be in EL a method expression or binding, you always need to be aware at least of the parameters that the JSF system will attempt to pass to your closure. With Value Change Listeners, JSF simply sends a single parameter, an instance of ValueChangeEvent.

The following example shows how to use a VCL closure with an input component:

Toggle Line Numbers
1 h.form { 
2     h.selectOneMenu(value: Value { someBean.value }, valueChangeListener: { evt -> 
3         if (evt.newValue != evt.oldValue) { 
4             log.info("value on some important entity has changed: $someBean.name -> from $evt.oldValue to $evt.newValue" 
5             someController.recordChange(someBean, evt.oldValue, evt.newValue) 
6             facesMessages.add("Change to important information (value) has been recorded")  
7         } 
8     }) 
9 } 
In the above example, we declare a single parameter, evt, which will be what JSF passes as the ValueChangeEvent. In the closure we check to see if the value has really changed, since sometimes this method will be called even though it is not really a different value. If it really has changed then we use the text log to record the change there, call a controller bean to handle any response to this change and the queue a message to the user that the change has been recorded.