Solved
HTL cannot access my custom Sling Model.
Hello.
HTL cannot access my simple Java Sling Model.
Here is my Sling Model sample. (Skipped the Interface because it is really simple.)
@Model(adaptables = Resource.class, adapters = MyComponent.class)
public class MyComponentImpl implements MyComponent{
@ValueMapValue(name = "fragmentPath", injectionStrategy = InjectionStrategy.OPTIONAL)
private String cfPath;
@SlingObject
private ResourceResolver resourceResolver;
private ContentFragment cf;
@PostConstruct
public void init() {
cf = resourceResolver.resolve(cfPath).adaptTo(ContentFragment.class);
}
public String getTitle() {
return cf.getElement("title").getContent();
}
}
and here is my HTL which call MyComponent's method.
<sly data-sly-use.templates="core/wcm/components/commons/v1/templates.html"
data-sly-use.model="foo.bar.core.models.MyComponent" />
<div data-sly-test="${model.title.length > 0}">
<span>${model.title @ context='html'}</span>
</div>
<sly data-sly-call="${templates.placeholder @ isEmpty=!properties.fragmentPath}"></sly>
and result...
org.apache.sling.scripting.sightly.render.ObjectModel Cannot access method title on object foo.bar.core.models.impl.MyComponentImpl@205d4d6f
This happens on AEM Cloud. On my local SDK, It's fine.
Please help me.