Use the Groovy character in a Grails controller

I would like to use the Groovy tag in the Grails controller in the following:

trait ColumnSelectionController { def selectColumns() { //Do something here } } class MyController implements ColumnSelectionController { def index() { //Calculate list model } } 

When I run this in Grails, the "selectColumns" action is not displayed, and I get a 404 response from Grails. I suspect that I need to do something with this attribute, so that the methods defined inside it are recognized as actions in the implementation class. Does anyone know what this could be?

EDIT 1:

Additional information: the attribute is defined in src / groovy, and not in grails-app / controller, therefore it is not defined as Artefact.

EDIT 2:

Also, if I change the trait in the class, mark it with the @Artefact annotation and change MyController to extend this class, everything will work as expected. Attempting to use the @Artefact annotation on the grounds of doing nothing (no big surprise).

+6
source share
1 answer

Just define the @Action annotation over a specific method in the attribute, this will make this method act as Action for the controller (when the traits are implemented)

 import grails.web.Action trait ColumnSelectionController { @Action def selectColumns() { //Do something here } } 

Hope this helps.

+6
source

Source: https://habr.com/ru/post/983332/


All Articles