Hello,
I am writing custom container component by extending AEM core container component. I am trying to use delegation pattern for updating a method. But delegation fails with Null Pointer Exception.
So far, I have AEM container component with sling:resourceSuperType="core/wcm/components/container/v1/container" set and no other logic set from frontend side. I created an interface ContainerModel.java extending Container model from
com.adobe.cq.wcm.core.components.models to have a testMethod as addition method. I created
ContainerModelImpl.class that implements ContainerModel.
My @Model looks like below.
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = { Container.class, ComponentExporter.class},
resourceType = ContainerModelImpl.RESOURCE_TYPE,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
The RESOURCE_TYPE is set as mysite/components/container pointing to container component. I am initializing delegate as below.
@Deleted Account
@Via(type = ResourceSuperType.class)
private Container delegate;
Now, all I am trying is to Override getId method that just returns delegate.getId() to test it out but it fails as well. Just a note that I am using Exporter as below.
@exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION
)
All other methods follow same logic and I am delegating to parent methods.
I am getting below warning and then null pointer exception pointing back to delegate.getId() statement.
*WARN* GET /content/mysite/us/en/mysitepage.model.json HTTP/1.1] org.apache.sling.models.impl.via.ResourceSuperTypeViaProvider Could not determine forced resource type for ResourceTypeForcingResourceWrapper, type=wcm/foundation/components/responsivegrid, path=/content/mysite/us/en/mysitepage/jcr:content/root, resource=[ResourceTypeForcingResourceWrapper, type=core/wcm/components/container/v1/container, path=/content/mysite/us/en/mysitepage/jcr:content/root, resource=[JcrNodeResource, type=mysite/components/container, superType=null, path=/content/mysite/us/en/mysitepage/jcr:content/root]] using via value .
Am I missing some additional requirements for delegating Container component? The warning mentions about wcm/foundation/components/responsivegrid. Do I need to configure something for that part? I am using delegation pattern for other components in same codebase with same approach but they are working fine and can initialize delegate as expected.