We are currently building a java DD4T 2 implementation. We are creating viewmodels for our different schema's. One of the schemas has a componentlink field that can link to either a multimedia component or a regular component.
Based on the documentation for viewmodels, we created an viewmodel interface and then created two specific viewmodels.
The resulting code looks a bit to this (the classes contain a lot more off course, but removed all the extra code for clarity.
public class Article extends AbstractModelClass {
@ViewModelProperty
private MultiMediaItem articleImage; //this can either be a regular component or a MM component
}
public interface MultiMediaItem
{
// ommitted interface properties for clarity
}
@ViewModel(rootElementNames = { "undefined" })
public class ArticleImageMultimediaComponent extends AbstractModelClass implements MultiMediaItem
//this defines the viewmodel for the Multimedia component
{
@ViewModelProperty(entityFieldName = "FileName")
private String fileName;
}
@ViewModel(rootElementNames = { "articleImageComponent" })
//this defines the viewmodel for the regular component
public class ArticleImageRegularComponent extends AbstractModelClass implements MultiMediaItem
{
@ViewModelProperty(entityFieldName = "textFieldFilename")
private String fileName;
}
The problem i'm having is that, normally, we should use the root element names of the schemas to let the databinder detect which class to instantiate (either the ArticleImageMultimediaComponent or the ArticleImageRegularComponent).
The problem is that the multimedia component doesn't have a root element name, so initially, the value of articleImage was always null. When we added the rootelementname "undefined" to the multimedia viewmodel, it started to work, and the databinder could resolve the multimedia component and convert it to our viewmodel.
It would be nice if we could use a different identifier for multimedia schemas (for example the schema title) instead of the 'untitled' root element name.
We are currently building a java DD4T 2 implementation. We are creating viewmodels for our different schema's. One of the schemas has a componentlink field that can link to either a multimedia component or a regular component.
Based on the documentation for viewmodels, we created an viewmodel interface and then created two specific viewmodels.
The resulting code looks a bit to this (the classes contain a lot more off course, but removed all the extra code for clarity.
The problem i'm having is that, normally, we should use the root element names of the schemas to let the databinder detect which class to instantiate (either the ArticleImageMultimediaComponent or the ArticleImageRegularComponent).
The problem is that the multimedia component doesn't have a root element name, so initially, the value of articleImage was always null. When we added the rootelementname "undefined" to the multimedia viewmodel, it started to work, and the databinder could resolve the multimedia component and convert it to our viewmodel.
It would be nice if we could use a different identifier for multimedia schemas (for example the schema title) instead of the 'untitled' root element name.