我使用的是一个非常基本的吊带模型类,它根本不起作用。这是一堂课:
package com.aem.sites.models.test;
import org.apache.sling.models.annotations.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import org.apache.sling.api.resource.Resource;
@Model(adaptables=Resource.class)
public class TestModel {
final static Logger logger = LoggerFactory.getLogger(TestModel.class);
private String email;
@PostConstruct
public void init() {
logger.info("=====================================================================inside init method");
email = "something@something.com";
}
public String getEmail() {
return email;
}
}我亦已把这个方案包括在这一节中:

我还在这里寻找Sling模型类,http://localhost:4502/system/console/status-adapters
发现这是这样的入口:
Adaptable: org.apache.sling.api.resource.Resource
Providing Bundle: org.apache.sling.models.impl
Available Adapters:
* com.aem.sites.models.test.TestModel更令我惊讶的是,包com.aem.sites.models.header中的Sling模型类正在被正确调用。
我不知道怎么回事。
提前感谢
共享HTL类:
<sly data-sly-use.bannerObj=com.aem.sites.models.test.TestModel">
<section id="banner"
style="background-image: url('/content/dam/aem-site/banner.jpg')">
<div class="inner">
<h2>Today's temperature is</h2>
<p>
${bannerObj.email}
</p>
<ul class="actions">
<li><a href="#content" class="button big special">Sign Up</a></li>
<li><a href="#elements" class="button big alt">Learn More</a></li>
</ul>
</div>
</section>
</sly>不工作,我的意思是什么都没有发生。error.log文件中没有出现错误或任何日志。
发布于 2017-10-10 05:23:16
我看到的唯一问题是语法错误,data-sly-use属性的值没有正确地用引号括起来。
<sly data-sly-use.bannerObj="com.aem.sites.models.test.TestModel">
<section id="banner"
style="background-image: url('/content/dam/aem-site/banner.jpg')">
<div class="inner">
<h2>Today's temperature is</h2>
<p>
${bannerObj.email}
</p>
<ul class="actions">
<li><a href="#content" class="button big special">Sign Up</a></li>
<li><a href="#elements" class="button big alt">Learn More</a></li>
</ul>
</div>
</section>
</sly>因此,HTL文件可能没有编译,并且没有编译就可以输出整个HTL。
发布于 2017-10-12 10:47:25
您可以从http://localhost:4502/system/console/status-slingmodels检查在您的实例中可用的Sling模型,以及它们绑定到哪些资源。
我会确保我的模型是列出的,然后检查其他类型的错误,如上面的注释中提到的打字错误。
https://stackoverflow.com/questions/46657368
复制相似问题