We have sling model. For example
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
private String propertyName;
}
public Image getPropertyName) {
return propertyName;
}
Also we have added
<Sling-Model-Packages>
org.apache.sling.models.it.models
</Sling-Model-Packages>
After this we can open edit dialog for this component and check that some data was inserted. We can see this data in JCR But when we are trying to get content of propertyName via Sightly
<div class="feature-wrapper" data-sly-use.model="org.apache.sling.models.it.models.MyModel">
<div data-sly-test="${model.propertyName}" data-sly-unwrap>
model.propertyName will be empty
Any ideas or advices? How I can debug Sling?
Can anyone add tag "Sightly" to this post?
It is possible that your bundle is importing the javax.inject.Inject
tag from the org.apache.sling.scripting.java
bundle as opposed to the Sling Models bundle. In AEM6 the org.apache.sling.scripting.java
bundle and the Sling Models bundle expose this package and if your bundle ends up getting the import from the former, Sling Models won't recognize your Import annotations.
I was able to get around this in my instance by adding <Require-Bundle>org.apache.sling.models.api</Require-Bundle>
to the maven-bundle-plugin configuration, essentially adding a Require-Bundle directive forcing my bundle to use org.apache.sling.models.api
bundle.
To find this, I downloaded the Sling source code from the Sling SVN repository, opened it in an IDE, and attached a debugger to my running AEM instance and set break points within the Sling Models bundle to see how the mechanism was attempting to resolve the import annotations.