Blogs
Add ADT to your portlets in just 4 steps
1. Custom PortletDisplayTemplateHandler
To join the exclusive ADT club your portlet has to sign a contract committing itself to fulfill all the ADT features. In other words, you have to create a your own PortletDisplayTemplateHandler implementation by extending the BasePortletDisplayTemplateHandler methods. You can check the TemplateHandler interface javadoc to learn what every method is for. Basically:
public class MyAppPortletDisplayTemplateHandler extends BasePortletDisplayTemplateHandler {
public String getClassName() {//Defines the type of entry your portlet is rendering}
public String getName(Locale locale) {//Declares the name of your ADT type (typically, the name of the portlet)}
public String getResourceName() {//Here you specify which resource is using the ADT (e.g. a portlet) for permission checking}
public String getTemplatesHelpPath(String language) {//Adds a custom hint to the top of the ADT in the template editor}
public String[] getRestrictedVariables(String language) {//Provides a list with the restricted variables}
public Map<String, TemplateVariableGroup> getTemplateVariableGroups(long classPK, String language, Locale locale) throws Exception {//Defines the variables exposed in the template editor}
}
<liferay-portlet-app> <portlet> <portlet-name>MyApp</portlet-name> … <template-handler> org.my.app.template.MyAppPortletDisplayTemplateHandler </template-handler> … </portlet> … </liferay-portlet-app>
2. Permissions
<resource-action-mapping> <portlet-resource> <portlet-name>MyApp</portlet-name> <permissions> <supports> <action-key>ADD_PORTLET_DISPLAY_TEMPLATE</action-key> … <supports> … <permissions> … <portlet-resource> … <resource-action-mapping>
3. Display settings configuration
<aui:form action="<%= configurationURL %>" method="post" name="fm">
...
<aui:fieldset>
<%
TemplateHandler templateHandler =
TemplateHandlerRegistryUtil.getTemplateHandler(MyType.class.getName());
%>
<liferay-ui:ddm-template-selector
classNameId="<%= PortalUtil.getClassNameId(templateHandler.getClassName()) %>"
displayStyle="<%= displayStyle %>"
displayStyleGroupId="<%= displayStyleGroupId %>"
refreshURL="<%= PortalUtil.getCurrentURL(request) %>"
showEmptyOption="<%= true %>"
/> </aui:fieldset>
...
</aui:form>
4. Render templates
<%
List<MyType> myList = ...;
long ddmTemplateId = PortletDisplayTemplateUtil.getPortletDisplayTemplateDDMTemplateId(
displayStyleGroupId, displayStyle);
Map<String, Object> contextObjects = new HashMap<String, Object>();
contextObjects.put("myExtraObject", someExtraObject);
%>
<c:choose>
<c:when test="<%= portletDisplayDDMTemplateId > 0 %>">
<%= PortletDisplayTemplateUtil.renderDDMTemplate(pageContext, ddmTemplateId, myList, contextObjects) %>
</c:when>
<c:otherwise>
...
</c:otherwise
</c:choose>
...
- Add your portlet to a page
- Edit configuration
- Display Settings selector is displayed (COOL!)
- Click Manage Display Settings and create new ADT
- The template editor displays your portlet variables (GREAT!)
- Save and choose your new ADT
- The portlet is rendered with your ADT (NICE!)
Demo

