【发布时间】:2017-10-10 01:34:49
【问题描述】:
我正在使用一个非常基本的 Sling Model 类,它根本不起作用。这是课程:
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;
}
}
我也在这个部分中包含了这个包:
我也在http://localhost:4502/system/console/status-adapters这里找了Sling Model类
发现它的条目是这样的:
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 Model 类被正确调用。
我不知道怎么了。
提前致谢
共享 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 文件中没有错误或任何日志。
【问题讨论】:
-
不工作是什么意思?你在哪里使用吊索模型?可以分享一下html吗?
-
用所需信息更新了我的帖子。
-
AEM 中加载的类会不会是旧版本?尝试完全卸载软件包,删除软件包,然后确保已删除捆绑包并且模型未显示在状态适配器中。然后重新部署您的项目。也只尝试 sling-model-packages 中的 com.aem.sites。只是为了消除任何类加载器问题。