Today we released version 2.0.7 of DD4T for Java. This version includes support for the Thymeleaf view language. Thymeleaf is a fast-growing view framework for Java web applications, which can be used as an alternative for JSP. I recently blogged about it as well.
Category Archives: DD4T
ViewModel functionality in DD4T 2.0 for Java Part III – Complex Field Types
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.
A new approach for serving images from a broker database
A picture says more than a thousand words, right? That’s why a web site needs images. In the old days before DD4T, the approach was very simple: out of the box, Tridion would publish your images to the file system, where the web server could pick them up and serve them out to the world.
But in the era of dynamic publishing, who wants to deploy to a file system anymore? One of the advantages of DD4T (or DXA, or any other dynamic framework) is that you publish everything to one central delivery store: the broker database. It makes sense to use this approach for images (and other binary file types) as well. But how?
Using the Thymeleaf view language
On a recent project of ours (Java/SDL Web 8/DD4T 2), the customer’s architect suggested to use a view language that I had – quite frankly – never heard of: Thymeleaf. I had always wondered why the Java world had never settled on a view technology to replace JSP. The way I see it, JSP has had a great run (it’s been around since 1999) but it belongs in the same category as ASP – a moloch from times of old. Although you can use JSP as the ‘V’ in ‘MVC’, it has never been a true view language. The support of inline java code means that developers can easily run amok, which can lead to messy and hard to maintain code bases. Also, JSP writes it output directly to the response, making it less flexible than more modern view technologies.
I have been waiting for a Java equivalent to .NET’s Razor: neat, clean syntax, intuitive switching between code and markup, and very well integrated into the framework. So when Thymeleaf was suggested, I thought – perhaps – this could be it!
DD4T: Page and Content ViewModels – an End-to-End Example
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.