Adapt Resource to a custom Model containing a Delegated model (AEM Core Component ImageImpl)
Hi all,
We have a Model called ImageModel which implements Image
The @Model annotation:
@Model(adaptables = {Resource.class, SlingHttpServletRequest.class}, adapters =
Image.class, resourceType = ImageModel.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
As we want to use the ImageV3 core component code we Inject the imageDelegate object like this
@Self
@Via(type = ResourceSuperType.class)
protected Image imageDelegate;
ImageModel.RESOURCE_TYPE is set to
myClient/components/image
Within a HTL template we can instantiate this model like this:
<picture data-sly-use.image="nl.dept.aem.myClient.core.models.ImageModel" etc... > etc... </picture>
This works fine, when attaching the debugger we can see the ImageModel has been instantiated with the imageDelegate beeing of class ImageImpl which is what we need to use the functionalities the image core component has to offer.
However,
When we grab the same resource from the JCR and adapt it to ImageModel.class the imageDelegate is now also of class ImageModel and it seems to have injected itself recursively
We are not quite sure how to adapt a Resource to our ImageModel and have the imageDelegate to be of class ImageImpl as with how AEM does this within the HTL templates
We did notice that the request object
@Self
protected SlingHttpServletRequest request;
Is instantiated correctly when the object is loaded from the HTL template
But this is null when we are adapting the resource.
Does anyone know what we are doing incorrectly? Or are we trying to achieve something that is just not supported?