Actions and Controller Closures or Methods?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Actions and Controller Closures or Methods?

mecorusfc
In my old 0.9 app that I'm converting to 2.6, I have some action definitions in the view that look similar to this:

                    action(id: 'varianceReportAction',
                            name: 'Run True-up Report',
                            closure: controller.trueUpReport,
                            smallIcon: imageIcon(url: model.goodUrl),
                            shortDescription: 'Run True-up Report'
                    )

In the controller, there is a closure for that.  If I take the word of the new documentation that says these closures are not supported and must all be converted to public methods (as I did), then I get an error saying that it can't find the closure.  If I convert them back to closures as they originally were, it seems to work but I'm concerned that I might be doing something wrong because the documentation seems pretty strict on this issue.  Ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Actions and Controller Closures or Methods?

aalmiray
Administrator
AFAIK you can still use the old way as long as you convert the method to a method closure, such as

                    action(id: 'varianceReportAction',
                            name: 'Run True-up Report',
                            closure: controller.&trueUpReport,
                            smallIcon: imageIcon(url: model.goodUrl),
                            shortDescription: 'Run True-up Report'
                    )

Notice the usage of the &. operator. However this will likely result in the wrong threading option being applied to the action itself. The alternative is to use the new format:

1. create a method on the controller named "varianceReport".
2. add key/values to griffon/i18n/messages.properties specifying the action's properties.

If the controller is named "com.acme.Sample" then the following keys should work

com.acme.Sample.action.VarianceReport.name=Run True-up Report
com.acme.Sample.action.VarianceReport.short_description=Run True-up Report
com.acme.Sample.action.VarianceReport.small_icon=path/to/icon/file

The ActionManager section at the Griffon Guide explains all properties and conventions that can be applied to actions.

Once an action is configured in this way it'll become available to Views as a builder variable, in this case "varianceReportAction".

Cheers,
Andres