[
https://wcm-io.atlassian.net/browse/WTES-16?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lei Zeng updated WTES-16:
-------------------------
Description:
When I inject AEM object Style like this in my Model.
{code:java}
@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class MyModel {
@AemObject
private Style currentStyle;
}
{code}
I got `java.lang.NullPointerException` that the sling model instance where adaptTo returned is null.
{code:java}
resource = context.create().resource("/content/test/jcr:content/nav");
context.currentPage("/content/test");
context.currentResource(resource);
context.addModelsForPackage("com.my.models");
myModel = resource.adaptTo(MyModel.class);
{code}
Do we have any solution to mock the Style or fix it inside AemContext ?
was:
When I inject AEM object Style like this in my Model.
{code:java}
@AemObject
private Style currentStyle;
{code}
I got `java.lang.NullPointerException` that the sling model instance where adaptTo returned is null.
Do we have any solution to mock the Style or fix it inside AemContext ?
> When com.day.cq.wcm.api.designer.Style injected in a Model, the adaptTo returns null
> ------------------------------------------------------------------------------------
> @Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
> public class MyModel {
> @AemObject
> private Style currentStyle;
> }
> {code}
> I got `java.lang.NullPointerException` that the sling model instance where adaptTo returned is null.
> {code:java}
> resource = context.create().resource("/content/test/jcr:content/nav");
> context.currentPage("/content/test");
> context.currentResource(resource);
> context.addModelsForPackage("com.my.models");
> myModel = resource.adaptTo(MyModel.class);
> {code}