4

I am new to java and was trying to write a model for a schema. I want to understand how a schema is linked with the model.

For e.g. I have schema with below details:

  1. heading (Text Field) - Single value
  2. menuLink (Embedded schema) - Multi value

[The embeded schema used here is 'link' which contains fields for creating a external or Tridion link]

When I write a model based on schema field names , it is something like

private String headline;
private List<Link> menuLink;

I also generate the getters and setters. I am able to display headline in my view, but not able to display any value from embedded fields i.e. menuLink

If I change this to:

private String headline;
//Changed to menuLinks instead of menuLink
private List<Link> menuLinks;

and generate getters and setters. This works fine with views.

The question here is why we need to use 'menuLinks' instead of 'menuLink' in the model even when the field name is menuLink? Is it because it is a multivalue field? How is this mapping done?

Also which datatype should be used for check-box while writing a model?

p.s. I do not have any guidelines for java MVC, so maybe I have missed something.

3
+50

According to the Tridion Reference Implementation (aka DXA) documentation, when default semantic mapping is used the naming convention of multi-value fields is defined as follows:

When attempting to populate a property of type List, remove any trailing s's from the property name. For example, the Paragraphs property is mapped to Schema field paragraph.

Meaning DXA by convention assumes properties in the Model to be named plural (ending with 's') for multi-value Schema fields.

  • 1
    Interesting and thanks for answering, Jeroen. I often see plural names on the Tridion-side for Schemas. Though technically, if you look at the XML, multi-value Schema fields should be singular, right? We get <menuLink/><menuLink/> rather than <menuLinks><menuLink/>...</menuLinks>. – Alvin Reyes Jul 28 '15 at 2:48
  • Thanks Jeroen. Still trying to understand the semantics concept though ; Wonder how would it work for a field name ending with s. For e.g. if field name is class? Also how can write a model for checkbox? – Huston Lopes Jul 28 '15 at 9:42
  • 1
    In the case of a multivalue field class DXA will strip the last 's' off so that would turn a bit ugly. In that case I would recommend using a semantic mapping, for instance: '[SemanticProperty("class")] public List<MyClass> classList;' – Jeroen Suurd Jul 29 '15 at 15:41
  • 1
    To model a checkbox in Tridion you would model a text field in the Schema with 'Values will be Selected from a List' using 'List type' is 'Check boxes', which means a property of type String in your model. – Jeroen Suurd Jul 29 '15 at 15:52
  • Thanks, I tried hard but couldn't use checkbox. Strangely dropdown was working. So using dropdown as of now. – Huston Lopes Aug 10 '15 at 11:43

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.