March 15, 2020
Estimated Post Reading Time ~

Basic Sling Model Exporter

/*
Open a page which is having component /apps/project/components/page/page
/content/project/en/jcr:content.model.json
Don't miss jcr:content in the path. Add jcr:content.model.json
*/

package com.org.project.models;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.jcr.Node;
import javax.jcr.RepositoryException; 

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Required;
import org.apache.sling.models.annotations.Source;
import org.apache.sling.models.annotations.injectorspecific.Self;
import com.day.cq.wcm.api.Page;

@Model(adaptables = Resource.class, resourceType = "/apps/project/components/page/page")

@Exporter(name = "jackson", extensions = "json")
public class PageModelExporter {

@Self
private Resource resource;

@Inject @Named("jcr:title") @Required
private String title;

@PostConstruct
private void init() {
}

public String getTitle() {
return title;
}
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.