Liferay Dynamic Data Mapping API provides comprehensive APIs for creating, managing, and processing dynamic forms and data structures within Liferay Portal.
—
Template processing system supporting FreeMarker, Velocity, and custom template languages for form and content rendering.
interface DDMTemplateManager {
Map<String, Object> getAutocompleteVariables(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Language language) throws Exception;
String[] getRestrictedVariables(Language language);
boolean isAutocompleteEnabled(Language language);
}
enum Language {
FREEMARKER("ftl"),
VELOCITY("vm"),
JAVASCRIPT("js");
String getExtension();
}interface DDMDisplay {
String getEditTemplateBackURL(HttpServletRequest httpServletRequest,
DDMTemplate template) throws PortalException;
String getViewTemplateBackURL(HttpServletRequest httpServletRequest,
DDMTemplate template) throws PortalException;
boolean isShowConfirmSelectStructure();
boolean isShowConfirmSelectTemplate();
}@Component
public class TemplateExample {
@Reference
private DDMTemplateLocalService templateLocalService;
public DDMTemplate createDisplayTemplate(long groupId, long structureId, long userId)
throws PortalException {
String script =
"<#list entries as entry>" +
" <div class=\"entry\">" +
" <h3>${entry.title}</h3>" +
" <p>${entry.description}</p>" +
" </div>" +
"</#list>";
Map<Locale, String> nameMap = Collections.singletonMap(Locale.US, "Entry Display Template");
Map<Locale, String> descriptionMap = Collections.singletonMap(Locale.US, "Template for displaying entries");
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
return templateLocalService.addTemplate(
userId, groupId,
PortalUtil.getClassNameId(DDMStructure.class), structureId,
PortalUtil.getClassNameId(DDMTemplate.class),
null, // auto-generate template key
nameMap, descriptionMap,
DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY,
DDMTemplateConstants.TEMPLATE_MODE_CREATE,
Language.FREEMARKER.getValue(),
script, true, // cacheable
false, null, null, // no small image
serviceContext
);
}
}Install with Tessl CLI
npx tessl i tessl/maven-com-liferay--com-liferay-dynamic-data-mapping-api