Skip to content

Instantly share code, notes, and snippets.

@sgaem
Last active June 10, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgaem/19d38af883877cbd77551b80103f8ffd to your computer and use it in GitHub Desktop.
Save sgaem/19d38af883877cbd77551b80103f8ffd to your computer and use it in GitHub Desktop.
This is the TestComponentModel.java, which can be used as sling Model Exporters.
package com.mycompany.myproject.sling.models;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.ExporterOption;
import org.apache.sling.models.annotations.Model;
import javax.inject.Inject;
import javax.inject.Named;
@Model(adaptables = Resource.class, resourceType = { "weretail/components/content/heroimage" }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = "jackson", extensions = "json", options = { @ExporterOption(name = "SerializationFeature.WRITE_DATES_AS_TIMESTAMPS", value = "true") })
public class ModelComponent {
@Inject
String title;
@Inject
String heading;
@Inject
String buttonLabel;
@Inject
String buttonLinkTo;
@Inject
String fileReference;
@Inject
@Named("sling:resourceType")
String slingResourceType;
public String getHeading() {
return heading;
}
public String getButtonLabel() {
return buttonLabel;
}
public String getButtonLinkTo() {
return buttonLinkTo;
}
public String getSlingResourceType() {
return slingResourceType;
}
public String getTitle() {
return title;
}
public String getFileReference() {
return fileReference;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment