Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

AEM 6.4 Model @Exporter for pages

Avatar

Level 2
Hello everyone,
im trying to export my model with @exporter.Somehow is not working and i guess it cold be because resourcetype.My model is for "pageanalytics" so the resourcetype should be something like:myapps/components/structure/pagebecause my model is called in head.html which is in page.If i remove the resorucetype the model is working but its not exported.if i put that path, its a null point and mypage.model.json is blank and not loadedWhat im doin wrong?
@Model(
        adaptables = SlingHttpServletRequest.class,
        adapters = ComponentExporter.class,
        defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
        resourceType = "myapp/components/structure/page")
@Exporter(
        name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
        extensions = ExporterConstants.SLING_MODEL_EXTENSION)
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

You need to do like

 

@Model(adaptables = SlingHttpServletRequest.class, adapters = {MyModel.class, ContainerExporter.class}, resourceType ="myapp/components/structure/page") 
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)


Arun Patidar

View solution in original post

4 Replies

Avatar

Community Advisor

Can you try something like

 

@Model(adaptables = SlingHttpServletRequest.class, adapters = {Page.class, ContainerExporter.class}, resourceType = PageImpl.RESOURCE_TYPE)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)

https://github.com/adobe/aem-core-wcm-components/blob/e49999b3733ceb487fd40774ac4a15f921713336/bundl... 



Arun Patidar

Avatar

Level 2

Hello, thank you for your answer.

Somehow i cannot do 

resourceType = PageImpl.RESOURCE_TYPE

Because my IDE doesnt recognize it.

public class MyModel extends ModelJsonExporter implements ComponentExporter{

 Could be because my model definition?

Avatar

Correct answer by
Community Advisor

Hi,

You need to do like

 

@Model(adaptables = SlingHttpServletRequest.class, adapters = {MyModel.class, ContainerExporter.class}, resourceType ="myapp/components/structure/page") 
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)


Arun Patidar

Avatar

Level 2

Yes this is the way, it was not working for some other issue.

Thanks a lot!