Plato (~423 BC – ~347 BC) was a pretty smart guy. Among his many ideas and thoughts, his Theory of Forms had an immense influence on how we perceive and solve the philosophical Problem of universals. It basically comes down to the idea that every physical object has one or more essences (or Forms) and that if that object would not have that Form, it would not be that object: a dog is Mammal, but a giraffe is also a Mammal. What makes both animals Mammals? It’s, simply put, the Idea of the Mammal.
In part II of these series on ViewModel functionality in dd4t–2-java, it was explained how to create ViewModel classes and how to implement basic field types for the mapping between Tridion fields and DD4T ViewModel properties.
This post handles the more complex field types. The reason we make a distinction between ‘simple’ and ‘complex’ is mainly because the complex field types have more options to be deserialized into and need quite some help from DD4T to know what they will become.
One of the unwritten rules in MVC is that ViewModel classes should be kept very simple. They should basically represent data to be displayed in your views. Then, depending on the concrete implementation and the requirements, the whole mapping and connecting it all together part does not always stay simple.
The usage of ViewModels in DD4T 2.0 can actually be very simple, as the example code will try to show. Anything with a simple basis should be also extendable in an easy way and that is the main goal of the framework.
In the previous article in this series, we had an in-depth look into how the ViewModels mechanism works in DD4T 2 for Java. This part covers the practical aspects and the basics on how to create your own ViewModels as well as having a look at how Tridion field types map to Java Object types.
As Quirijn already announced eloquently in his post on ViewModels in DD4T 2.0, the idea of making it easier to build a Tridion driven website for developers by introducing the ability to use simple model classes in your MVC application serving Tridion data, is one of the biggest improvements in the DD4T framework. With the public coming-out-of-beta release of DD4T 2.0 for Java, ViewModel functionality has also been fully integrated in the Java version of the framework. This series of posts focus on how ViewModels work in DD4T 2.0 for Java.