You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Julian Sedding (Jira)" <ji...@apache.org> on 2021/08/17 08:26:00 UTC

[jira] [Commented] (SLING-10738) Sling Model inheritance breaks with component exporter

    [ https://issues.apache.org/jira/browse/SLING-10738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17400242#comment-17400242 ] 

Julian Sedding commented on SLING-10738:
----------------------------------------

[~cshawaus] I would assume that your class needs to implement {{ComponentExporter}} and {{ContainerExporter}} as well as {{LayoutContainer}} (BTW your current code implements {{LayoutContainer.class}}, that doesn't look correct. I assume you mean just {{LayoutContainer}}).

I expect that your error.log file may contain further information about what is happening. My guess would be that you find a {{ClassCastException}} due to the missing implemented interfaces.

> Sling Model inheritance breaks with component exporter
> ------------------------------------------------------
>
>                 Key: SLING-10738
>                 URL: https://issues.apache.org/jira/browse/SLING-10738
>             Project: Sling
>          Issue Type: Bug
>          Components: Sling Models
>            Reporter: Chris Shaw
>            Priority: Major
>
> Hi,
> I'm currently supporting a project where I need to extend the LayoutContainer class in AEM Core Components. Completing this process was easy and straightforward when solely dealing solely with Sling Model Delegation. Shortly after confirming this behaviour was working correctly, I added Adobe's *ContainerExporter.class* to the *@Model* adapters and noticed that Sling Model Delegation stopped working.
> I am raising this issue here first because the same method of extending models in AEM Core Components works without issue except for the LayoutContainer model. Below is the basic code before adding the exporters.
> {code:java}
> @Model(
>         adaptables = SlingHttpServletRequest.class,
>         adapters = {LayoutContainer.class},
>         resourceType = CustomContainerImpl.RESOURCE_TYPE,
>         defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
> )
> public class CustomContainerImpl implements LayoutContainer.class {
>     protected static final String RESOURCE_TYPE = "project/components/custom-container";
>     @Self
>     @Via(type = ResourceSuperType.class)
>     private LayoutContainer layoutContainer;
>     
>     // ... implementation
> }
> {code}
> With this code, no issues at a page level are observed and all inherited behaviours work as expected including appending *.model.json* to the page URL.
> Once I move beyond this and apply the exporter adapters, *.model.json* no longer works correctly and Sling Model Delegation breaks completely.
> {code:java}
> @Model(
>         adaptables = SlingHttpServletRequest.class,
>         adapters = {LayoutContainer.class, ComponentExporter.class, ContainerExporter.class},
>         resourceType = CustomContainerImpl.RESOURCE_TYPE,
>         defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
> )
> public class CustomContainerImpl implements LayoutContainer.class {
>     protected static final String RESOURCE_TYPE = "project/components/custom-container";
>     @Self
>     @Via(type = ResourceSuperType.class)
>     private LayoutContainer layoutContainer;
>     
>     // ... implementation
> }
> {code}
> Note that the adapters are: *ComponentExporter.class* and *ContainerExporter.class*.
> What can be observed are 2 key issues:
>  # The *layoutContainer* property always returns *null*
>  # The previous JSON structure containing *root* elements is always empty for child pages
> As a workaround to at least ensure the inheritance works, I have reverted to using a *ModelFactory* instance which works from an authoring perspective but doesn't solve the JSON output issue.
> {code:java}
> layoutContainer = modelFactory.getModelFromWrappedRequest(
>     request,
>     request.getResource(),
>     LayoutContainer.class);{code}
> It would be great to get insight into this as I was to be 100% sure Sling is not to blame before raising an issue with Adobe.
> Thanks for your time!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)