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)
  • 1
    Can you specify how you load your component presentation from the broker ? Do you get this using the DXA API , or are you direcly calling the broker API to get the component presentation ? – Harald Hoffelinck Oct 11 at 8:49
  • @HaraldHoffelinck I am directly calling the broker API to get the component presentation. – Rache Oct 14 at 6:51

You should use the DXA API functions to retrieve that kind of content, instead of the regular Broker API.

The reason for that is that, these DXA API functions call the model service that takes care of these link resolving for you (or in case of earlier DXA versions, those functions also perform link resolving for you).

The function you need to call is the ContentProvider.GetEntityModel(string id, ILocalization localization). This function will return an EntityModel, which you can then use in your controller.

All DXA controllers inheriting from the BaseController have a ContentProvider property that you can use.

One more note : the string id attribute you need to pass is not just the TCM uri of the entity you want to retrieve, it is a combination of the item id of the component, and the item id of the template (from the documentation : <param name="id">The Entity Identifier. Must be in format {ComponentID}-{TemplateID}.</param>

  • I had first used that function but I was getting an exception which I have added to my original question. That's how I ended up using Broker API. – Rache Oct 17 at 9:32
  • Regarding your exception, can you check this question/answer - it seems very similar to that ambiguous mapping error you are seeing - tridion.stackexchange.com/questions/19396/… – Harald Hoffelinck Oct 19 at 7:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.