Chris Shaw created SLING-10738:
----------------------------------
Summary: 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
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 {
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 {
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)