Expand my Community achievements bar.

How to read public List<NavigationItem> getItems()

Avatar

Level 2

I have this on my custom component

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Footer"
sling:resourceSuperType="demo/components/navigation"
componentGroup="Content"/>

Since I extend navigation I want to list some pages but I cant achieve that, this is how I tried:

@ProviderType
public interface FooterModel extends Navigation {

}

 

@Model(adaptables = SlingHttpServletRequest.class, adapters = {FooterModel.class, ComponentExporter.class}, resourceType = FooterModelImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class FooterModelImpl implements FooterModel, ComponentExporter {
@Model(adaptables = SlingHttpServletRequest.class, adapters = {FooterModel.class, ComponentExporter.class}, resourceType = FooterModelImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class FooterModelImpl implements FooterModel, ComponentExporter {

static final String RESOURCE_TYPE = "demo/components/footer";

@Self
private SlingHttpServletRequest request;

@Self
@Via(type = ResourceSuperType.class)
private Navigation navigation;


@Override
public String getExportedType() {
return FooterModelImpl.RESOURCE_TYPE;
}

@Override
public List<NavigationItem> getItems() {
return null != navigation ? navigation.getItems() : null;
}

@Override
public String getAccessibilityLabel() {
return null != navigation ? navigation.getAccessibilityLabel() : null;
}
}

 getAccesibiliyLabel works fine and I get it on JSON but getItems() not

1 Reply

Avatar

Community Advisor

Ensure the Navigation.class is also an adaptor.