[ https://issues.apache.org/jira/browse/SLING-10738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17405697#comment-17405697 ]
Julian Sedding edited comment on SLING-10738 at 8/27/21, 9:14 AM: ------------------------------------------------------------------ [~cshawaus] I've finally taken the time to check this out. For me it works flawlessly with {{org.apache.sling.models.impl}} version {{1.4.16}}. Or I am testing the wrong thing. I am requesting {{/content/demo/us/en.model.json}} and I get lots of rendered JSON, which includes the property "myCustomProperty". Note: I did remove your workaround for the tests. One thing I noticed is that you set the default injection strategy to "optional". I don't understand why, but in any case you should at least make the "layoutContainer" field "required" in order to fail early and hopefully get a meaningful error message in the logs. If I misunderstood your problem, please advise on how to test with a few simple bullet points. was (Author: jsedding): [~cshawaus] I've finally taken the time to check this out. For me it works flawlessly, or I am testing the wrong thing. I am requesting {{/content/demo/us/en.model.json}} and I get lots of rendered JSON, which includes the property "myCustomProperty". Note: I did remove your workaround for the tests. One thing I noticed is that you set the default injection strategy to "optional". I don't understand why, but in any case you should at least make the "layoutContainer" field "required" in order to fail early and hopefully get a meaningful error message in the logs. If I misunderstood your problem, please advise on how to test with a few simple bullet points. > 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 { > 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 { > 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)