6

We have a view model with a property as a multi valued Linked Component (Linked to a single Schema). We have created the models like:

@SemanticEntity(entityName = "schemarootname", vocabulary = SDL_CORE, prefix = "", public_ = true)
public class MainModel extends AbstractEntityModel {

    private String title;

    private List<componentlinkedmodalclass> items;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public List<componentlinkedmodalclass> getItems() {
        return items;
    }

    public void setItems(List<componentlinkedmodalclass> items) {
        this.items = items;
    }

}

@SemanticEntity(entityName = "schemarootname1", vocabulary = SDL_CORE, prefix = "", public_ = true)
public class componentlinkedmodalclass extends AbstractEntityModel {

    private String title;


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

}

Get and Set method is defined in the model. In the schemas.json file I can see semantic definition for main schemas like:

{
    "Id": 36661,
    "RootElement": "schemarootname",
    "Fields": [{
            "Name": "title",
            "Path": "/schemarootname/title",
            "IsMultiValue": false,
            "Semantics": [{
                "Prefix": "tri",
                "Entity": "schemarootname",
                "Property": "title"
            }],
            "Fields": []
        }, {
            "Name": "items",
            "Path": "/schemarootname/items",
            "IsMultiValue": true,
            "Semantics": [{
                "Prefix": "tri",
                "Entity": "schemarootname",
                "Property": "items"
            }],
            "Fields": []
        }
    },

However this field is not binding in the view model.

I have tried to debug the issue by just having a single field in the modelclass without any luck. I am using DXA Java 1.6 with SDL Tridion 2013 SP1. To simplify the question I have removed other fields from model and semantics. Can anyone suggest what I am missing.

2
  • Can you edit your question and provide some more details on the Schema and semantic mapping if used? Commented Apr 14, 2017 at 6:56
  • @Bart, I have updated my question with model definition. Commented Apr 14, 2017 at 7:59

2 Answers 2

7

I think the problem here is that the implicit semantic mapping "de-pluralizes" the name of a list-type property. So, a property called "items" implicitly maps to a CM field called "item".

However, as visible in the schemas.json fragment you provided, your CM field is called "items" too. This means you will need an explicity semantic mapping: add a @SemanticProperty("items") annotation on your View Model property.

3

After generating trace level log, I was able to identify that issue is because of the creating view model with default mapping. In Trace log it was showing error message:

05:56:16.770 [http-nio-8080-exec-2] TRACE c.s.w.c.i.mapping.SemanticMapperImpl - No match found for field: private java.util.List modelclass.items; registry semantics: [FieldSemantics(vocabulary=SemanticVocabulary(id=http://www.sdl.com/web/schemas/core, prefix=null, vocab=null), entityName=modelclass, propertyName=item)]  

Thanks Rick. When I was posting my findings in the answer, I have seen you have already posted the answer. I have added the semantic property to the field and issue got resolved. Few learning here:

  • Useful to generate trace level log in case you face strange model mapping issue. In debug log you might miss the detailed log about field mapping issue.

  • Property with List type(in my case items) is by default mapped to a
    singular name(item). So if there is any change in this relation add
    semantic property to the model.

Your Answer

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

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