4

I'm implementing DD4T Java version 2. I saw following article. http://blog.trivident.com/2014/12/introducing-dd4t-version-2-0-for-java/

According to this article, it's possible to deserialize component data to model class. So I created a component tempate, which has "H1" on view metadata. And component has "heading" field, and its schema's root element name is "GeneralHeading".

Then I created following modle class

package org.dd4t.springmvc.model;

import org.dd4t.databind.annotations.ViewModel;
import org.dd4t.databind.annotations.ViewModelProperty;
import org.dd4t.databind.viewmodel.base.TridionViewModelBase;

@ViewModel(
viewModelNames = {"H1"},
rootElementNames = "GeneralHeading")
public class H1Model extends TridionViewModelBase {
    @ViewModelProperty(entityFieldName = "heading")
    public String heading;

    public void setHeading(String heading){
        this.heading=heading;
    }

    public String getHeading(){
        return this.heading;
    }

}

Also I created following JSP view "H1.jsp".

<%@page import="org.dd4t.springmvc.constants.Constants"%>
<%@page import="org.dd4t.springmvc.siteedit.SiteEditService"%>
<%@ page 
    language="java" contentType="text/html; charset=UTF-8"
    import="org.dd4t.springmvc.view.model.*,
            org.dd4t.contentmodel.*,
            org.dd4t.contentmodel.impl.*"
    pageEncoding="UTF-8"%>

<jsp:useBean id="H1" type="org.dd4t.springmvc.model.H1Model" scope="request"/>

heading:${H1.heading}

But it causes following error.

javax.servlet.ServletException: java.lang.InstantiationException: bean H1 not found within scope

What I'd like to ask is following.

  • Is it necessary to create new class by myself on DD4T to do this?
  • Which value should be specified to @ViewModel annotation and id attribute of jsp:useBean of JSP?

Update

I'm not sure this is correct approach, but I succeed to make it work by following way.

  1. Open WEB-INF\dispatcher-servlet.xml and edit following elements. Find bean element with ID attribute "dataBinder". Set "false" on value of property element "renderDefaultComponentModelsOnly". Specify package which is model class is created in, on property "viewModelPackageRoot".
  2. Then NullPointerException occurs at org.dd4t.springmvc.siteedit#generateSiteEditComponentTag,because cp.getComponent() returns null. So add logic to handle when this property is null.
  3. Add model instance to request's attribute, it can be gotten from cp.getAllViewModels().

Regards,

  • This is now fixed for you right? – Raimond Mar 5 '16 at 16:53
  • I'm running into this same problem. Has this been fixed? – Piti Itharat May 3 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.