-2

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.

  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – Stefan Becker Jan 31 '19 at 06:29

1 Answers1

1

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

[1] https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/adobe/acs/samples/models/SampleSlingModel.java

David J
  • 300
  • 1
  • 7