How to access Sling Model in JAVA class that extends WCMUse/WCMUsePojo
Hi Team,
Is it possible to get the Sling model in the class that extends WCMUse/WCMUsePojo? I tried the below code in Sightly class but I'm getting null-
MySlingModel mySlingModel = getResource().adaptTo(MySlingModel.class);
if (null != mySlingModel ) {
LOG.info("mySlingModel IS NOT NULL");
} else {
LOG.info("mySlingModel IS NULL:");
}
I tried the below scenarios also but I'm getting NULL -
- MySlingModel mySlingModel = getRequest().getResourceResolver().getResource(getResource().getPath()).adaptTo(MySlingModel.class);
- MySlingModel mySlingModel = getRequest().adaptTo(MySlingModel.class);
Is it good practice do use Sling Models in sightly class?
Thanks,
AryA.