如何从我的自定义 portlet 为新期刊文章添加结构和模板?

How to add structure and template for new journal article from my custom portlet?

将新的期刊文章放入页面时,:

这是我的要求(比如当我们将 web 内容显示 portlet 放到页面中时,在单击添加按钮时,它将打开一个页面并显示选项选择结构,当我们 select 选择结构,它会将结构 ID 和与结构 ID 关联的模板 ID 附加到期刊文章中)。

如何实现?

您可以参考以下代码片段来为自定义 portlet 中的 Web 内容添加结构和模板

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
                Long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
                DDMStructure ddmStructure=DDMStructureLocalServiceUtil.getDDMStructure(11515);
                DDMTemplate ddmTemplate=DDMTemplateLocalServiceUtil.getDDMTemplate(11517);
                Map<Locale,String> titleMap=new HashMap<Locale,String>();
                titleMap.put(themeDisplay.getLocale(), "First Record");
                String content=
                        "<root available-locales='en_US' default-locale='en_US'>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Title' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                    +"<dynamic-content>FirstRecord</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Description' readOnly='false' repeatable='false' required='false' showLabel='true' type='textarea' width='small'>"
                                +"  <dynamic-content>This the first one doing by programatically</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='image' fieldNamespace='wcm' indexType='keyword' name='DamImage' readOnly='false' repeatable='false' required='false' showLabel='true' type='wcm-image' width=''>"
                                +"  <dynamic-content>http://localhost:8080/documents/10184/0/welcome_community/0dc0adb1-b565-409a-b766-96d1e42b04fb?t=1459163274526</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='UserIdExcel' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                +"  <dynamic-content>458155</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Username' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                +"  <dynamic-content>LaxmanDeepak</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='date' fieldNamespace='ddm' indexType='keyword' name='DateFromExcel' readOnly='false' repeatable='false' required='false' showLabel='true' type='ddm-date' width='small'>"
                                +"<dynamic-content>03/29/2016</dynamic-content>"
                                +"</dynamic-element>"
                            +"</root>";
                ServiceContext serviceContext = new ServiceContext();
                serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());
                serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

                JournalArticleLocalServiceUtil.addArticle(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), parentFolderId, titleMap, null, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), serviceContext);