Message Boards

Template for ADT in custom portlet is not being displayed

thumbnail
Abhishek Jain, modified 7 Years ago.

Template for ADT in custom portlet is not being displayed

Regular Member Posts: 226 Join Date: 8/20/16 Recent Posts
I made a custom portlet. I made a template handler class for that portlet . The portlet containing template handler class is deployed successfully. But there is no entry for the template in the Site Admin* → Configuration → Application Display Templates->Add(+)->Template. The template handler class is as follows:-

package com.test.template;

import com.example.model.CustomUser4;
import com.liferay.portal.kernel.portletdisplaytemplate.BasePortletDisplayTemplateHandler;
import com.liferay.portal.kernel.template.TemplateHandler;
import com.liferay.portal.kernel.template.TemplateVariableGroup;
//import com.liferay.portal.kernel.template.TemplateHandler;
//import com.liferay.portal.kernel.template.TemplateVariableGroup;
import com.liferay.portlet.portletdisplaytemplate.util.PortletDisplayTemplateConstants;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.osgi.service.component.annotations.Component;


@Component(
immediate = true,
property = {
"javax.portlet.name=com_example_portlet_BlogPortletmvcportletPortlet"
},
service = TemplateHandler.class
)
public class StudentPortletDisplayTemplateHandler extends BasePortletDisplayTemplateHandler{

@Override
public String getClassName() {
return CustomUser4.class.getName();
}

@Override
public String getName(Locale locale) {

//String students = LanguageUtil.get(locale, "students");

return "student_template";
}

@Override
public String getResourceName() {
System.out.println("getResourceName");
return "com_example_portlet_BlogPortletmvcportletPortlet";
}

@Override
public Map<String, TemplateVariableGroup> getTemplateVariableGroups(
long classPK, String language, Locale locale)
throws Exception {

Map<String, TemplateVariableGroup> templateVariableGroups =
super.getTemplateVariableGroups(classPK, language, locale);

TemplateVariableGroup templateVariableGroup =
templateVariableGroups.get("fields");

templateVariableGroup.empty();

templateVariableGroup.addCollectionVariable(
"students", List.class, PortletDisplayTemplateConstants.ENTRIES,
"student", CustomUser4.class, "curStudent", "name");

return templateVariableGroups;
}


}