I created the following annotation:
public @interface NavAnnotation {
boolean addToAdminMenu() default false;
}
… then try to annotate a domain class:
@NavAnnotation ( addToAdminMenu = true )
class Information {...}
… and do something with that in a controller:
def appDomainClasses = grailsApplication.domainClasses.findAll {
it.class.isAnnotationPresent( NavAnnotation )
}
[ appDomainClasses : appDomainClasses ]
… but that annotated class is not getting picked up. Any ideas on what I’m missing?
Couple things…
1.) Ensure that your annotation has a retention policy of
@Retention(RetentionPolicy.RUNTIME). The RUNTIME retention policy allows the annotation to be available for reflection at runtime. So your interface should look like….2.)
grailsApplication.domainClassesreturns aDefaultGrailsDomainClassand not the actual class you want to preform reflections on. Instead you want to access the underlining class using the getClazz() method like this….I’ve tested to confirm that it works. Enjoy!
-Thanks