4

When we have Page meta data schema and we have field with multimedia or text field whose value is derived from the Category/Keywords then DXA 1.2 doesn't resolve them to the proper values, instead it has the hash value like below

org.dd4t.contentmodel.impl.KeywordImpl@6b4c37a1 org.dd4t.contentmodel.impl.ComponentImpl@49d1c6b3

DXA code below

PageBuilderImpl.java is the class and the methodName processMetadataField(final Field field)

        **final String fieldName = field.getName();**

        String value;
        **switch (fieldName) {**
            case "internalLink":
                final String componentId = ((BaseField) field).getTextValues().get(0);
                try {
                    value = linkResolver.resolve(componentId);
                } catch (SerializationException | ItemNotFoundException e) {
                    LOG.warn("Error while resolving link: {}", componentId);
                    value = componentId;
                }
                break;
            case IMAGE_FIELD_NAME:
                value = ((BaseField) field).getLinkedComponentValues().get(0).getMultimedia().getUrl();
                break;
            default:
                value = Joiner.on(',').join(field.getValues());
                break;
        }

        if (!(StringUtils.isEmpty(value) || result.containsKey(fieldName))) {
            result.put(fieldName, value);
        }

The switch case is on the field name. Then its restriction on the schema XML field naming, which is not generic implemenation

  • it is working fine in earlier version of dxa.net. Could you just debug it, using opensource DD4T code. – Raj Kumar Jan 25 '16 at 8:37
2

I have found the solution for the issue, Implemented in the generic way so that it would cater for all the scenarios and below is the code fix required. In the PageBuilderImpl.java is the class and the methodName processMetadataField(final Field field)

final String fieldName = field.getName();

    FieldType fieldType = field.getFieldType();            
    String value;
    // changed the switch on the fieldType rather on the field name
    switch (fieldType) {
    //removed the internal link String to COMPONENTLINK FieldType
        case COMPONENTLINK:
            final String componentId = ((BaseField) field).getTextValues().get(0);
            try {
                value = linkResolver.resolve(componentId);
            } catch (SerializationException | ItemNotFoundException e) {
                LOG.warn("Error while resolving link: {}", componentId);
                value = componentId;
            }
            break;
         // changed the image String to the MultimediaLink field
        case MULTIMEDIALINK:                    
          value = ((BaseField) field).getLinkedComponentValues().get(0).getMultimedia().getUrl();                    
            break;
         // added the new case for keyword field as this would have value in getTextValues
        case KEYWORD:
             value = Joiner.on(',').join(((KeywordField) field).getTextValues());
            break;
        default:        
             value = Joiner.on(',').join(field.getValues());                 
             break;
    }
  • Glad you were able to solve it :). – Shiva Jan 25 '16 at 14:42

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.