Skip to content

Instantly share code, notes, and snippets.

View OSGi Service
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategyzOPTIONAL)
public class ContactUsModel {
@Inject
private ResourceResolver resourceResolver;
}
View currentStyle-from-Resource
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ContactUsModel {
private Style currentStyle;
private Designer designer;
@PostConstruct
protected void init() {
// Getting the currentStyle from the Designer.class
designer = this.resourceResolver.adaptTo(Designer.class);
View currentStyle
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategyzOPTIONAL)
public class ContactUsModel {
@Inject
private Style currentStyle;
}
View Self
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ContactUsModel {
//Accessing the resource that is adapted to ContactusModel
@Self
protected Resource resource;
}
View Via
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ContactUsModel {
@Inject @Via("resource")
private String title;
}
View Named
@Inject @Named("jcr:created")
private String created;
View Default
@Inject @Default(values="Contact Us")
private String title;
@Inject @Default(intValues={1,2,3,4})
private int[] integers;
View Model-SlingHttpServletRequest
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
View Model-Resource
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
View Optional-Required
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ContactUsModel {
private String mailAddress;
private String phoneNumber;
@Inject
@Required
protected String title;
You can’t perform that action at this time.