How to create Structure & Template programmatically in Liferay 6

前端 未结 1 2004
轻奢々
轻奢々 2021-01-15 15:35

I need to create the Structure and Template progrmatically through java code.I used following code snippets.

Structure:

public void          


        
相关标签:
1条回答
  • 2021-01-15 15:45

    There are couple of issues with your code:

    1. You are not setting all the required properties, like groupId, companyId, classNameId, structureKey, dates etc.

    2. There isn't any setName and setDescription method for DDMStructure or DDMTemplate accepting String argument (Liferay 6.2 GA2). Instead, there are only setNameMap and setDescriptionMap methods for both accepting Map<Locale, String>.

    3. Use dynamic ids (structureId and templateId) in place of hard-coded ids, as following: DDMStructure ddmStructure = DDMStructureUtil.create(CounterLocalServiceUtil.increment());and DDMTemplate ddmTemplate = DDMTemplateUtil.create(CounterLocalServiceUtil.increment());

    4. For classNameId, you can get it using it's value, like:
      ClassName className = ClassNameLocalServiceUtil.getClassName("com.liferay.portlet.journal.model.Journ‌​alArticle"); long classNameId = className.getClassNameId();

    5. Also, better to use update over populated object in place of adding: DDMStructureUtil.update(ddmStructure); and DDMTemplateUtil.update(ddmTemplate);

    Additionally, if you have access to the ThemeDisplay object, you can get groupId, companyId, userId, userFullName from it. Also, set new Date() for createDate and modifiedDate properties.

    0 讨论(0)
提交回复
热议问题