In Sling Model, the model class is annotated as @Model(adaptables = Resource.class)
What is the significance of passing the param as adaptables = Resource.class. What if I don't pass any parameter. What all parameter @Model accepts.
In Sling Model, the model class is annotated as @Model(adaptables = Resource.class)
What is the significance of passing the param as adaptables = Resource.class. What if I don't pass any parameter. What all parameter @Model accepts.
The adaptables
property determines what source objects can be adapted to the Sling model implementation. Typically this is Resource
and/or SlingHttpServletRequest
, meaning a Sling resource or Sling request object respectively.
In most common use-cases you can use the default adaption strategy combined with the other OOTB model annotations. For advanced cases you can implement your own adapter to control how this is done.
If you don't specify an adaptables
type then I don't expect the model will allow you to instantiate it via the adaptTo()
method. I doubt if you will be able to manually instantiate it ModelFactory
service either.
For details about the various Sling Model annotations and options check the Sling documentation [0], it has just about all the information you should need. There are also good examples in the ACS AEM Samples project [1].
[0] https://sling.apache.org/documentation/bundles/models.html