One of the ContentModelData
returns content in the below format.
Code 1
content = {question=Question 1?, answer={paraContent=RichTextData(fragments=[No. Answer 1 <strong>Strong text here</strong> Answer continues <br /> Answer para 2.])}}
question has value of type String
, and answer is a list of paragraphs containing heading
, list of paraContent
. List of paracontent
is actually a list of RichText
. Now sometimes paraContent
is simply a list of RichText
fields but when we create RichText Data, RichTextData
fragments are created. I have tried many methods.
Code 2
1. paraMultiLevel= (List<ParagraphMultiLevel>)
content.getAndCast("answer", ParagraphMultiLevel.class);
2. paraMultiLevel2 = (List<ParagraphMultiLevel>)content.getElement("answer");
3. (List<ParagraphMultiLevel>)content.get("answer")
None of the above populates my entity viewModel
. I am getting an exception
com.sdl.dxa.api.datamodel.model.ContentModelData cannot be cast to java.util.List
How can I fetch the Answer
value and set it on a List <List<ParagraphMultiLevel>
so I can access it in my view?
Update on 04/04/2018
When I originally tried to convertEntites(List<ComponentMetadata>)
(see code 3), it returned null
values so then I had to manually iterate over the list of ids and got the EntityModelData
using DefaultModelService.loadEntity()
.
From the EntityModelData
I get the ContentModelData
(see Code 1). I want to set my customTeaser.content
with ContentModelData.get("answer")
.
Code 3
try { dynamicList.setQueryResults(customContentProvider._convertEntities(components, dynamicList.getEntityType(), localization), query.isHasMore());
} catch (DxaException e) {
throw new ContentProviderException("Cannot populate a dynamic list " + dynamicList.getId() + " localization " + localization.getId(), e);
}
returned [ContentTeaser(headline=null, introduction=null, content=null,...
Code 4
@SemanticEntities({
@SemanticEntity(entityName = "FAQs", vocabulary = SDL_CORE, prefix = "f")
})
public class ContentTeaser extends AbstractEntityModel {
@JsonProperty("Headline")
private String headline;
@SemanticProperty("f:question")
@JsonProperty("Introduction")
private String introduction;
@SemanticProperty("f:answer")
@JsonProperty("Content")
private List<ParagraphMultiLevel> content;
}
Code 5
@SemanticEntity(entityName = "ParagraphMultiLevel", vocabulary = SDL_CORE, prefix = "pml")
@Data
@EqualsAndHashCode(callSuper = true)
public class ParagraphMultiLevel extends AbstractEntityModel {
@SemanticProperty("pml:heading")
@JsonProperty("Heading")
private String heading;
@SemanticProperty("pml:paraContent")
@JsonProperty("ParaContent")
private List<RichText> paraContent;
@SemanticProperty("pml:subParagraph")
@JsonProperty("SubParagraph")
private List<SubParagraphLevel2> subParagraph;
@SemanticProperty("pml:paraFootnote")
@JsonProperty("ParaFootnote")
private List<RichText> paraFootnote;
}
ContentModelData
) is only expected in Model Builders, which is considered an advanced extension point which is normally not needed.