AEM Page Exporter – Doesn’t include components with multifields

I’m trying to export a page with the default model exporter of AEM. This page contains multiple components and some of them have multifields. When I visit homepage.model.json the JSON doesn’t have the multifields.

carousel: {
    :type: "mysite/components/public/carousel",
    title: "Test title"
}

I’ve searched everywhere for a solution. Everywhere on the internet they suggest to make an Exporter for my component:

@Model(adaptables = Resource.class,
        defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
        resourceType = {"mysite/components/public/carousel"})
@Exporter(name = "jackson", extensions = "json")

public class CarouselModelImpl implements CarouselModel, ComponentModel {

...
@Getter
    private List<CarouselBean> slides;
...

So when I visit

homepage/jcr:content/carousel.model.json I get the correct JSON:

{
    title: "Test title",
    slides: [
    {
        title: "slide title 1",
        description: null,
        ctaLabel: "cta label",
        ctaLink: "#",
        image: "/content/dam/mysite/Rectangle 2.png"
    },
    {
        title: "slide title 2",
        description: null,
        ctaLabel: "cta label",
        ctaLink: "#",
        image: "/content/dam/mysite/image.png"
    }
    ],
}

But when I visit the homepage.model.json it’s still not included:

carousel: {
    :type: "mysite/components/public/carousel",
    title: "Test title"
}

So from what I understand I have 2 options:

  1. To make a Page Exporter and have a lot of custom code.

  2. Accept that I can’t have a page with all the JSON data that I want.

I tried to make a custom Page Exporter with the logic to iterate all the children and sub-children in order to get the correct JSON with minimal code. I try to get the Exporter Models for each component, but the modelFactory is null.

@Model(adaptables = Resource.class,
        defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
        resourceType = {"mysite/components/public/structure/public-page"})
@Exporter(name = "jackson", extensions = "json")
public class PageExporterServlet {

    private static final Logger log = LoggerFactory.getLogger(PageUtils.class);

    @Reference
    private ModelFactory modelFactory;

    @Reference
    private SlingScriptHelper slingScriptHelper;

    @Self
    private Resource resource;

    @Getter
    private String myTitle = "Test";

    @Getter
    Map<String, Object> pageData = new HashMap<>();

    @PostConstruct
    // PostConstructs are called after all the injection has occurred, but before the Model object is returned for use.
    protected void init() {
        try {
            processResource(resource, pageData);
        } catch (Exception e) {
            log.debug(e.getMessage());
        }
    }

    private void processResource(Resource resource, Map<String, Object> pageData) {
        if (resource != null) {
            Iterable<Resource> childResources = resource.getChildren();
            for (Resource childResource : childResources) {
                ComponentModel componentModel = (ComponentModel) modelFactory.getModelFromResource(childResource);
                if (componentModel != null) {
                    pageData.put(childResource.getPath(), componentModel.getData());
                } else {
                    // If the resource is not a component, recursively process its children
                    processResource(childResource, pageData);
                }
            }
        }
    }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật