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

In AEM SPA com.adobe.aem.spa.project.core.models not found

Avatar

Level 7

I have to override and modify getExportedPath() present inside spa page core model. I cannot find that in my import. I can find core component page but not the aem.spa.project.core but I can find the dependency are available even in system/console/bundle it is available and active 

Ronnie09_0-1685107054799.png



For dispatcher I need to over ride and shorten the URL how can I do that if it is not available

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Ronnie09,

This is expected, because implementation of models is part of internal package, which is not exported. You can find implementation under:

You should use delegate pattern in case you want to made some modification. This is standard approach for models from Core Components, and SPA models are not exception here.

Sample code, that should give you an idea which direction to go.

 

package com.example.page;

import com.adobe.aem.spa.project.core.models.Page;
import com.adobe.cq.export.json.ContainerExporter;
import com.adobe.cq.export.json.ExporterConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;
import org.jetbrains.annotations.Nullable;

import java.util.Calendar;

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

    static final String RESOURCE_TYPE = "custom/page/resource";

    @Self
    @Via(type = ResourceSuperType.class)
    private Page delegate;

    @Override
    public String getExportedPath() {
        // place for your implementation
    }

    // other methods from Page, use methods from delegate if you do not want change them y
    @Override
    public @Nullable Page getHierarchyRootModel() {
        return delegate.getHierarchyRootModel();
    }

    @Override
    public String getLanguage() {
        return delegate.getLanguage();
    }

    @Override
    public Calendar getLastModifiedDate() {
        return delegate.getLastModifiedDate();
    }

    @Override
    public String[] getKeywords() {
        return delegate.getKeywords();
    }

    // repeat for all other methods from Page
}

 

 

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @Ronnie09,

This is expected, because implementation of models is part of internal package, which is not exported. You can find implementation under:

You should use delegate pattern in case you want to made some modification. This is standard approach for models from Core Components, and SPA models are not exception here.

Sample code, that should give you an idea which direction to go.

 

package com.example.page;

import com.adobe.aem.spa.project.core.models.Page;
import com.adobe.cq.export.json.ContainerExporter;
import com.adobe.cq.export.json.ExporterConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;
import org.jetbrains.annotations.Nullable;

import java.util.Calendar;

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

    static final String RESOURCE_TYPE = "custom/page/resource";

    @Self
    @Via(type = ResourceSuperType.class)
    private Page delegate;

    @Override
    public String getExportedPath() {
        // place for your implementation
    }

    // other methods from Page, use methods from delegate if you do not want change them y
    @Override
    public @Nullable Page getHierarchyRootModel() {
        return delegate.getHierarchyRootModel();
    }

    @Override
    public String getLanguage() {
        return delegate.getLanguage();
    }

    @Override
    public Calendar getLastModifiedDate() {
        return delegate.getLastModifiedDate();
    }

    @Override
    public String[] getKeywords() {
        return delegate.getKeywords();
    }

    // repeat for all other methods from Page
}

 

 

 

Avatar

Level 7

Hi @lukasz-m 

com.adobe.aem.spa.project.core.models.Page

this page is not coming up while overriding the Page

Ronnie09_1-1685110508870.png

 

 

Avatar

Community Advisor

Make sure you have included below dependency in your project pom. As it provides SPA project api.

<dependency>
   <groupId>com.adobe.aem</groupId>
   <artifactId>spa.project.core.core</artifactId>
   <version>1.3.12</version>
</dependency>

 

Avatar

Level 7

@lukasz-m 
Oh I forgot this thanks I can see it now.

I have overridden all the methods but all methods are returning null 

    private Page delegate;


this delegate via debugger I found that it is not null still methods are returning null.