THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
Table of Contents |
---|
Many Sling projects want to be able to create model objects - POJOs which are automatically mapped from Sling objects, typically resources, but also request objects. Sometimes these POJOs need OSGi services as well.
...
Code Block | ||
---|---|---|
| ||
@Model(adaptables=SlingHttpServletRequest.class)
public interface MyModel {
@Inject @Projection("resource")
String getPropertyName();
} |
Annotation Reference
- @Model - declares a model class or interface
- @Inject - marks a field or method as injectable
- @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.
- @Filter - an OSGi service filter
- @PostConstruct - methods to call upon model option creation (only for model classes)
- @Projection - project a JavaBean property as the adaptable.
- @Default - set default values for a field or method
Available Injectors
- Value Map (valuemap) - adapt the adaptable to a ValueMap and retrive properties.
- OSGI Services (osgi-services) - lookup services based on class name (including List and Array support). Effectively ignores name.
- Script Bindings (script-bindings) - gets script bindings from request and looks up by name.
- Child Resources (child-resources) - gets child resources by name.
- Request Attributes (request-atttributes) - gets request attributes