7

I'm implementing DD4T 2 Java version.

When a component have only one keyword value in it's field, DD4T gets 4 same keyword values. For instance, a component has only one keyword, which is "Keyword", DD4T gets 4 "Keyword" values as if same keyword is specified in one field 4 times.

It seems a problem of DD4T default templates. When previewing a page on CME, rendered JSON include multiple keywords.

Result of page preview is follwing. "TEST KEYWORD" is selected on a component's field.

   "Fields": {
                    "heading": {
                        "DateTimeValues": [], 
                        "FieldType": 0, 
                        "KeywordValues": [], 
                        "Keywords": [], 
                        "LinkedComponentValues": [], 
                        "Name": "heading", 
                        "NumericValues": [], 
                        "Value": "Keyword Test", 
                        "Values": [
                            "Keyword Test"
                        ], 
                        "XPath": "tcm:Content/custom:KeywordTest/custom:heading"
                    }, 
                    "keyword": {
                        "CategoryId": "tcm:65-17-512", 
                        "CategoryName": "Font Size", 
                        "DateTimeValues": [], 
                        "FieldType": 3, 
                        "KeywordValues": [
                            {
                                "Description": "", 
                                "Id": "tcm:65-1606-1024", 
                                "Key": "", 
                                "MetadataFields": {}, 
                                "ParentKeywords": [], 
                                "Path": "\Font Size\TEST KEYWORD", 
                                "TaxonomyId": "tcm:65-17-512", 
                                "Title": "TEST KEYWORD"
                            }, 
                            {
                                "Description": "", 
                                "Id": "tcm:65-1606-1024", 
                                "Key": "", 
                                "MetadataFields": {}, 
                                "ParentKeywords": [], 
                                "Path": "\Font Size\TEST KEYWORD", 
                                "TaxonomyId": "tcm:65-17-512", 
                                "Title": "TEST KEYWORD"
                            }, 
                            {
                                "Description": "", 
                                "Id": "tcm:65-1606-1024", 
                                "Key": "", 
                                "MetadataFields": {}, 
                                "ParentKeywords": [], 
                                "Path": "\Font Size\TEST KEYWORD", 
                                "TaxonomyId": "tcm:65-17-512", 
                                "Title": "TEST KEYWORD"
                            }, 
                            {
                                "Description": "", 
                                "Id": "tcm:65-1606-1024", 
                                "Key": "", 
                                "MetadataFields": {}, 
                                "ParentKeywords": [], 
                                "Path": "\Font Size\TEST KEYWORD", 
                                "TaxonomyId": "tcm:65-17-512", 
                                "Title": "TEST KEYWORD"
                            }, 

How can I fix this problem?

Regards,

UPDATE:

In ContentModel.cs, there are propeties "Keywords" and "KeywordValues", and both of them use "KeywordValues" in set and get. In this case, when "Deserialize" is called from BaseComponentTemplate class, number of keyword field's value increase twofold. So Those properies should be separeted like following.

public List<Keyword> Keywords
        {
            get;
            set;
        }
        [XmlIgnore]
        IList<IKeyword> IField.Keywords
        {
            get { return Keywords.ToList<IKeyword>(); }
        }

        public List<Keyword> KeywordValues
        {
            get;
            set;
        }
        [XmlIgnore]
        IList<IKeyword> IField.KeywordValues
        {
            get { return KeywordValues.ToList<IKeyword>(); }
        }

After that, modify source code where using those properties,ContentModel.cs and FieldBuilder.cs.

  • 1
    It turned out this is a problem of default TBB. It can be fixed by customizing source code.I updated my question and add how to fix it. – Hirokazu Shikata Aug 13 '15 at 8:42
  • Could you add this as an answer? Thanks a lot. I'll make sure this gets fixed in the to-be released version – Albert Romkes Aug 14 '15 at 10:23
4

You were right, this was a big fat bug in DD4T. I've fixed it, a little differently from your suggestion. I want 'Keywords' (which was an inconsistent name we accidentally introduced) to be an alias to KeywordValues, while in your suggestion they would be completely independent.

I fixed it by adding a 'ShouldSerializeKeywords' method, as described here: http://www.newtonsoft.com/json/help/html/ConditionalProperties.htm.

To fix, proceed as follows:

  • Check out the latest develop branch of dd4t-2-templates (https://github.com/dd4t/dd4t-2-templates/tree/develop)

  • Change the NuGet package reference to the dd4t-2-model package to use the version number DD4T.Model.2.0.3-alpha21

  • Build the solution in Visual Studio

  • Run the install-templates.bat file in \dd4t-2-templates\tools\template-installer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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