У меня есть SlingModel под названием TextModel
.SlingModel не соответствует JCR правильно
@Model(adaptables=Resource.class, defaultInjectionStrategy= DefaultInjectionStrategy.OPTIONAL)
public class TextModel {
@Inject
private String heading;
@Inject
private String description;
public String getHeading() {
return heading;
}
public String getDescription() {
return description;
}
}
У меня также есть шаблон в красивый, которая делает компонент:
<div data-sly-use.model="project.components.slingmodels.text.TextModel" data-sly-unwrap/>
<div>
<p>PageModel component</p>
<h1>${model.heading}</h1>
<p>Description: ${model.description}</p>
</div>
Тогда я встраивать компонент на странице:
<div data-sly-resource="${@ resourceType='project/components/textModel'}" data-sly-unwrap></div>
И создать первоначальную структуру JCR через JSON:
{
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "project/pages/page",
"title" : "Welcome page",
"jcr:content" : {
"myContent" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType" : "project/components/textModel",
"heading": "Heading",
"description": "test description"
}
}
}
Все поля правильно сохранены в JCR, но моя модель Sling возвращает null как значение как heading
, так и description
.
Но, когда я создаю содержимое так:
{
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "project/pages/page",
"title" : "Welcome page",
"heading": "Heading",
"description": "test description",
"jcr:content" : {
"myContent" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType" : "project/components/textModel"
}
}
}
Он работает. JSON хранится под jcr_root/content/hello.json
в моих файлах проектов, и я открываю URL-адрес localhost:8080/content/hello.html
в своем браузере.