Implementation: Currently we have schema with a component link field called 'link'. I've enabled multiple value, so authors can have multiple component links from now on instead of only 1 (there's already a lot of components with a single component 'link'). I can see the following happening (source of component), simplified:
<MyComponent>
<titel>This is my component with multiple value component links enabled</titel>
<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="tcm:1-23456" xlink:title="Link 1"></link>
<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="tcm:1-23457" xlink:title="Link 2"></link>
</MyComponent>
Now there are 2 link elements.
In order to make this working, I needed to change my model for this entity. The easiest way is to make this as a list:
@SemanticProperty("link")
private AbstractEntityModel linkedSingleEntity;
@SemanticProperty("link")
private List<AbstractEntityModel> linkedEntities;
The linkedEntities
will replace the linkedSingleEntity
in this case.
Problem: When I have 1 component link, DXA doesn't process the list. The published schema doesn't match with the model in the webapp. But when I have 2 or more component links, DXA will process the links. If there is none, there is nothing to process so it won't fail either this way.
Error (replaced some 'company related' info with 'custom'):
14:31:19.464 [http-nio-9085-exec-6] ERROR n.s.s.d.c.CustomContentProviderImpl - Fatal exception for item [tcm:33-327558]; The published content from Tridion doesn't meet the current entity model. Is the Tridion schema changed? - java.lang.IllegalArgumentException: Can not set java.util.List field nl.custom.customweb.site.custom.model.Winitem.linkedEntities to nl.custom.customweb.site.custom.model.Kennisitem
My findings: I think I discoverd the problem. It seems to be in the DXA templating on CMS side. When having 1 component link, and I preview the component with DXA templating, I see the link isn't processed as a multiple value list:
"Content": {
"titel": "This is my component with multiple value component links enabled",
"link": {
"$type": "EntityModelData",
"Id": "327651",
"ComponentTemplate": {
"Id": "5483",
"RevisionDate": "0001-01-01T00:00:00"
},
"Folder": {
"Id": "16148",
"Title": "z_Test"
},
"Content": {
When having 2 (or more) links, the JSON shows as follows:
"Content": {
"titel": "This is my component with multiple value component links enabled",
"link": {
"$type": "EntityModelData[]",
"$values": [
{
"Id": "327651",
"ComponentTemplate": {
"Id": "5483",
"RevisionDate": "0001-01-01T00:00:00"
},
"Folder": {
"Id": "16148",
"Title": "z_Test"
},
"Content": {
Suddenly we have $values[]
in place.
Question: What should be the way to handle this. Please take in mind we already have published content with the not-multiple-value-component-links-enabled (creating embed schema for comp links is not really an option). And, this is a bug, right?
Environment info:
- Tridion 8.6 (also tested it on 9.5; same issue)
- DXA 2.2.3 Java
- DXA 2.0 templating in Tridion 8.6; DXA 2.2 templating in Tridion 9.5 (same issue)
EntityModelData
, whereas multiple values are represented as an array of that type. This is regardless of whether the field is multi-valued or not in the Schema. The semantic mapping logic (in the DXA Web App Framework) is very flexible and can map single values to lists and vice versa.14:31:19.464 [http-nio-9085-exec-6] ERROR n.s.s.d.c.CustomContentProviderImpl - Fatal exception for item [tcm:33-327558]; The published content from Tridion doesn't meet the current entity model. Is the Tridion schema changed? - java.lang.IllegalArgumentException: Can not set java.util.List field nl.custom.customweb.site.custom.model.Winitem.linkedEntities to nl.custom.customweb.site.custom.model.Kennisitem
From model perspective I get different formats.*.Kennisitem
objects within a list. But it can also be an individual item which isn't a list in this case. How do I manage this in my model?null
if there are no Component Links). So, what you're trying to do (two properties mapping to the same CM field) should just work. I'm quite sure it worked properly in the past. Maybe it got broken in some recent DXA patch release (?)