By default DXA resolves Component Links in Rich Text field and Component Link fields when rendering the components directly. But when we get the contents as a result of our broker Query and then manipulate the population of our model view, during this process, we see that our content renders the url as a string and does not resolve the component link url.
ContentModelData answer = modelData.getContent().getAndCast("answer", ContentModelData.class);
TypeInformation typeInformation =
TypeInformation.builder().objectType(String.class).build();
TypeInformation typeInformation =
TypeInformation.builder().objectType(RichTextData.class).build();
RichTextData rtd = answer.getAndCast("paraContent", RichTextData.class);
//RichText rt = new RichText((String)converter.convert(rtd, typeInformation, null, null, null));
lt.add(converter.convert(rtd, typeInformation, null, null, null));
RichTextData(fragments=[Please Click here])
where my RichText is (fragments=[Please <a title="Dining List" href="tcm:27-4850" >Click here</a> <!--CompLink tcm:27-4850-->])
How can I resolve the tcm links in my richText contentData?
Additional Information:
com.sdl.webapp.tridion.fields.exceptions.FieldConverterException: Cannot convert a entity model 16761 to class com.sdl.dxa.modules.products.model.Products for semantic field productName
at com.sdl.dxa.tridion.mapping.converter.EntityModelDataConverter.convert(EntityModelDataConverter.java:43)
at com.sdl.dxa.tridion.mapping.converter.EntityModelDataConverter.convert(EntityModelDataConverter.java:17)
at com.sdl.dxa.tridion.mapping.converter.GenericSemanticModelDataConverter.convert(GenericSemanticModelDataConverter.java:65)
.... ....
Caused by: com.sdl.webapp.common.exceptions.DxaException: Exception happened while creating a entity model from: EntityModelData(id=16761, componentTemplate=ComponentTemplateData(id=169, title=null, revisionDate=0001-01-01T00:00:00.000Z, outputFormat=null, metadata=null), linkUrl=null, content={visuals={visualSize=KeywordModelData(id=644, description=null, key=null, taxonomyId=null, title=null), visualImage=EntityModelData(id=15390, componentTemplate=ComponentTemplateData(id=169, title=null, revisionDate=0001-01-01T00:00:00.000Z, outputFormat=null, metadata=null), linkUrl=null, content=null, binaryContent=BinaryContentData(fileName=products-15390_v20.jpg, fileSize=342991, mimeType=image/jpeg, url=/en/media/products-15390_v20_tcm27-15390.jpg), externalContent=null)}, extraLinks={targetFrame=KeywordModelData(id=405, description=null, key=null, taxonomyId=null, title=null)}, title=Title, introduction=Some introduction text here}, binaryContent=null, externalContent=null)
at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.buildEntityModel(DefaultModelBuilder.java:133)
at com.sdl.dxa.tridion.mapping.impl.ModelBuilderPipelineImpl.createEntityModel(ModelBuilderPipelineImpl.java:86)
at com.sdl.dxa.tridion.mapping.converter.EntityModelDataConverter.convert(EntityModelDataConverter.java:37)
... 134 common frames omitted
Caused by: com.sdl.webapp.common.exceptions.DxaException: Cannot get a view model tpe because of semantic mapping exception
at com.sdl.webapp.common.impl.model.ViewModelRegistryImpl.getMappedModelTypes(ViewModelRegistryImpl.java:109)
at com.sdl.webapp.common.impl.model.ViewModelRegistryImpl.getMappedModelTypes(ViewModelRegistryImpl.java:78)
at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.buildEntityModel(DefaultModelBuilder.java:107)
... 136 common frames omitted
Caused by: com.sdl.webapp.common.api.mapping.semantic.SemanticMappingException: Ambiguous semantic mapping for http://www.sdl.com/web/schemas/core:Products, found these mappings: [class com.sdl.dxa.modules.products.model.Products, class com.sdl.dxa.modules.products.model.Products]
at com.sdl.webapp.common.impl.mapping.SemanticMappingRegistryImpl.getEntityClassByFullyQualifiedName(SemanticMappingRegistryImpl.java:334)
at com.sdl.webapp.common.impl.model.ViewModelRegistryImpl.getMappedModelTypes(ViewModelRegistryImpl.java:107)
... 138 common frames omitted
Finally the EntityModel I get is this, where all my metadata fields (productName, faqsByProducts,faqsByTopic...) are null. I need these because I need this for filtering.
FAQs(question=How can you ask a question?, answer=[ParagraphMultiLevel(heading=null, paraContent=[Please contact our call center on <a href="tel:1xxxxxxx">xxxxxxx</a>], subParagraph=null, paraFootnote=null)], productName=null, faqsByProducts=null, faqsByTopic=null, active=Tag(displayText=null, key=360, tagCategory=null), analyticsTitle= Personal - How can you ask a question? {0} [7169] [EN], productTag=null, linkedURL=null, faqId=null, topViewedCategory=null, topViewedCount=null)