package demo
import grails.web.api.WebAttributes
class Helper implements WebAttributes {
List<String> getControllerNames() {
// There is no need to pass grailsApplication as an argument
// or otherwise inject the grailsApplication property. The
// WebAttributes trait provides access to grailsApplication.
grailsApplication.getArtefacts('Controller')*.name
}
}
9.1 Traits Provided by Grails
Version: 3.2.4
Table of Contents
9.1 Traits Provided by Grails
Grails artefacts are automatically augmented with certain traits at compile time.
Domain Class Traits
-
org.grails.datastore.gorm.GormEntity
-
org.grails.datastore.gorm.GormValidateable
Controller Traits
Interceptor Trait
Tag Library Trait
Service Trait
Below is a list of other traits provided by the framework. The javadocs provide more detail about methods and properties related to each trait.
Trait | Brief Description |
---|---|
Common Web Attributes |
|
Servlet API Attributes |
|
Data Binding API |
|
Request Forwarding API |
|
Response Redirecting API |
|
Response Rendering API |
|
Validation API |
9.1.1 WebAttributes Trait Example
WebAttributes is one of the traits provided by the framework. Any Groovy class may implement this trait to inherit all of the properties and behaviors provided by the trait.
src/main/groovy/demo/Helper.groovy
The traits are compatible with static compilation…
src/main/groovy/demo/Helper.groovy
package demo
import grails.web.api.WebAttributes
import groovy.transform.CompileStatic
@CompileStatic
class Helper implements WebAttributes {
List<String> getControllerNames() {
// There is no need to pass grailsApplication as an argument
// or otherwise inject the grailsApplication property. The
// WebAttributes trait provides access to grailsApplication.
grailsApplication.getArtefacts('Controller')*.name
}
}