1

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)
6
  • The difference you observed in the DXA R2 JSON is "by design". A Component Link field with a single value is represented as type 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. May 12, 2021 at 6:39
  • Try setting the log level to DEBUG and have a look at the DXA log file; it provides information what happens during the semantic mapping. May 12, 2021 at 6:41
  • @RickPannekoek It doesn't seem so simple; The error I get is as follows (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 From model perspective I get different formats.
    – Harmen
    May 12, 2021 at 12:43
  • @RickPannekoek Point is, I've got a list of *.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?
    – Harmen
    May 12, 2021 at 12:55
  • If all is well, DXA semantic mapping happily maps a single-value Component Link to a list property (list will contain only one item) and a multi-valued Component Link to a non-list property (property will reflect the first Component Link or be 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 (?) May 12, 2021 at 15:18

2 Answers 2

2

I did try to reproduce this issue in DXA 2.2.5 Java, but it couldn't able to reproduce this issue, it actually works for me in the OOTB DXA Core module as expected. same I also try to reproduce this issue in DXA 2.2.9 .NET there also not an issue. It's working fine, I can confirm that DXA Webapp Framework not having an issue for the multi-value field for single value vs multi-value, the above R2 JSON is expected.

I doubt that your Semantic model mapping is something missing in your web app.

Here are the steps, I did try to reproduce this issue.

  1. In CME in the existing DXA Core module Article schema - added new field link as component link type field and enabled multi-value enter image description here

  2. Since Article schema is using vocabulary = SCHEMA_ORG, Updated the tcm:ExtensionXml for the schematic mapping enter image description here

  3. Updated one of the About page with the Article component to added one component in the link field and published About and page settings pages. enter image description here

  4. In the Core module updated Article.java model for the new field

    @SemanticProperty("s:link")
    private List<Article> linkComps;
  1. In the Core module updated Article.jsp View for the new field to display
 <c:forEach var="linkComp" items="${entity.linkComps}" varStatus="status">
    <c:if test="${not empty linkComp.headline}">
          <h3>${linkComp.headline}</h3>
     </c:if>
 </c:forEach>

Output (as expected):

enter image description here

As @Rick mentioned in his comment.

  • The fact that DXA R2 JSON using a single value for a single Component Link (or any field type for that matter) and an array for multiple Component Links is by design.
  • Indeed, this is different than for DD4T JSON (DXA 1.x), which uses an array as soon as the Schema field is multi-valued (even if you only have a single value).
  • The DXA semantic mapping (in the DXA Web App Framework) is supposed to be very flexible and happily map a single value to list property or an array to a non-list property.

So, here there is no problem with the DXA R2 JSON and DXA Web App Framework, as you can see in my steps and result.

0

Bug is confirmed by SDL/RWS:

8.5 + DXA 1.7 -- issue not present 
8.5 + DXA 2.0 -- issue present 
9.5 + DXA 2.2 -- issue present

I don't know if they will fix it in the next release; DXA is not actively supported by SDL/RWS.

Edit: Rick seems to be right after all. This issue was caused by one of our own converter classes.

1
  • This analysis is incorrect; the "issue not present" means that DXA 1.x uses DD4T and there is a difference between how multi-valued fields in DD4T JSON vs DXA R2 JSON. Neither are defective, though. If there is an issue in DXA 2.2.3 Java, it has to be in the semantic mapping logic in the DXA Web App Framework. May 25, 2021 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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