SlingHttpServletRequest request is null in slingmodel
i want to adapt to sling model from another sling model. While doing so the SlingHttpServletRequest request is always null in second sling model. i tried with @Inject, @self and @@SlingObject. I am able to get request in FirstModel but not in SecondModel, i believe this happens because SecondModel is getting adapted with resource. Had anyone faced this issue and how it worked..
Thanks in advance
basically my code is simlilar to:
@Model(
adaptables = {SlingHttpServletRequest.class, Resource.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class SecondModel {
@Inject
private SlingHttpServletRequest request;
}
@Model(
adaptables = SlingHttpServletRequest.class,
resourceType = "mycomponent path",
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class FirstModel {
@Inject
private SlingHttpServletRequest request;
@PostConstruct
public void initResource() {
SecondModel obj = request.getResourceResolver().getResource(resourcePath).adaptTo(SecondModel .class)
}
}