我正在通过实用的博客。我有如下简单的使用类:
public class SightlyDemo2 extends WCMUse {
private String fullName;
@Override
public void activate() {
fullName = get("firstName", String.class) + " " + get("lastName", String.class);
}
public String getFullName() {
return fullName;
}
}
我通过 .html 文件中的以下代码成功调用它:
<div data-sly-use.aemComponent="${'org.practice.sightly.SightlyDemo2' @ firstName= 'AEM', lastName = 'CQ5'}">
${aemComponent.fullName}
</div>
它工作正常,但是当我尝试创建适配器类时,它停止渲染全名。下面是适配器代码。
@Component(metatype = true, immediate = true)
@Service
public class SightlyDemo2Adapter implements AdapterFactory {
@Property(name = "adapters")
protected static final String[] ADAPTER_CLASSES = {SightlyDemo2.class.getName()};
@Property(name = "adaptables")
protected static final String[] ADAPTABLE_CLASSES = {Resource.class.getName()};
@Override
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (adaptable instanceof Resource) {
SightlyDemo2 comp = new SightlyDemo2();
return (AdapterType) comp;
}
return null;
}
}
我想使用自定义适配器,例如:
SightlyDemo2 obj = resource.adaptTo(SightlyDemo2.class);
任何想法。
谢谢