3

Is it possible to know if a Schema field was multivalued or not in a the DD4T 2.0 Java web application?

I am writing a bit of generic code and want to know whether a field is multi-value or not in even if it has only one item.

I suspect the only way is to write something to publish the schema info (a la DXA mappings) or write a custom TBB which places this info in the JSON and look for that.

Am I right on this? I don't see anything on the Field interface or FieldType enum.

1 Answer 1

1

We ran into a similar issue and unfortunately there isn't anything available OOB to get this information. I don't recall of the exact version of the DD4T that we used.

We ended up injecting a value using TBB in xpath on the fields and then on the RESTful api side used dd4t to serialize the objects, read the value from XPath that we injected and generated an array in the JSON response (if the value set was multi value on the XPath) and then removed the same from XPath

2
  • You wouldn't happen to have open sourced the code would you @vipin? Commented Apr 7, 2017 at 10:19
  • The code is not open source and I couldn't make it either. The tricky/hacky part was where to add the information so that I can avoid cascading effect of changing dd4t presentation (which would happen if I add a new attribute on the field). So, we picked Xpath attribute and added there and no change on dd4t presentation. Also, oData doesn't return schema information, so TBB was the only option available when we implemented this Commented Apr 7, 2017 at 16:26

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.