Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing a viewmodel proporty for a componentlinkfield that can link to both regular components and multimedia components #85

Open
HaraldHoffelinck opened this issue Mar 2, 2017 · 0 comments

Comments

@HaraldHoffelinck
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants