Model annotations for different adaptables
Hi,
Annotation Description
@Model declares a model class or interface
@Inject marks a field or method as injectable
@Self Injects the adaptable itself. If the field type does not match with the adaptable it is tried to adapt the adaptable to the requested type
@Named declare a name for the injection (otherwise, defaults based on field or method name)
@Optional marks a field or method injection as optional
@Source explictly tie an injected field or method to a particular injector (by name). can also be on other annotations.
@PostConstruct methods to call upon model option creation (only for model classes)
@Via change the adaptable as the source of the injection
@Default set default values for a field or method
@ScriptVariable Injects the script variable defined via Sling Bindings. If name is not set the name is derived from the method/field name
@ValueMapValue Injects a ValueMap value. If via is not set, it will automatically take resource if the adaptable is the SlingHttpServletRequest. If name is not set the name is derived from the method/field name
@RequestAttribute Injects a request attribute by name. If name is not set the name is derived from the method/field name
@OSGiService Injects an OSGi service by type. The filter can be used give an OSGi service filter
@SlingObject Injects commonly used sling objects if the field matches with the class: request, response, resource resolver, current resource, SlingScriptHelper
Is there any specific documentation on which annotation is valid for which adaptable (Resource vs SlingHttpRequest), For example: I could not use @scriptvariable Page currentPage if adaptable is Resource.class. currentPage returns null.
I would need documentation or API which tells which annotations provide what all objects and which annotations are valid for Resource, SlingHttpRequest adaptables.
I looked at this documentation but doesnot clearly says what annotations are valid for which adaptables.
https://sling.apache.org/documentation/bundles/models.html
Any API classes implementation source code to look at also fine.