我尝试为Liferay 6.2 DDL提供阅读服务。
这是DDL结构:
<root available-locales="en_US" default-locale="en_US">
<dynamic-element dataType="string" indexType="text" localizable="false" name="Course_ID" readOnly="false" repeatable="false" required="true" showLabel="true" type="text" width="medium">
<dynamic-element dataType="boolean" indexType="keyword" localizable="true" name="Active" readOnly="false" repeatable="true" required="false" showLabel="true" type="checkbox" width="">
<dynamic-element dataType="string" indexType="keyword" localizable="true" multiple="false" name="Language" readOnly="false" repeatable="false" required="false" showLabel="true" type="select" width="">
<dynamic-element name="option22436" type="option" value="en">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[English]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element name="option22437" type="option" value="fr">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[French]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element name="option22438" type="option" value="de">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Deutsch]]>
</entry>
</meta-data>
</dynamic-element>
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Language]]>
</entry>
<entry name="predefinedValue">
<![CDATA[[""]]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="string" indexType="keyword" localizable="true" name="Guest_URL" readOnly="false" repeatable="false" required="false" showLabel="true" type="text" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Guest URL]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="string" indexType="keyword" localizable="true" name="Registered_URL" readOnly="false" repeatable="false" required="false" showLabel="true" type="text" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Registered URL]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Active]]>
</entry>
<entry name="predefinedValue">
<![CDATA[true]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="document-library" fieldNamespace="ddm" indexType="keyword" localizable="true" name="Documents_and_Media8331" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-documentlibrary" width="">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Documents and Media]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Course ID]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
</root>
正如你所看到的,我有一个可重复的复选框容器,里面还有3个元素 structure view
我可以获取并迭代记录列表,但不知道如何获得包含所有复选框的列表并迭代其内部元素
DynamicQuery getRecordsetIdQuery = DDLRecordSetLocalServiceUtil.dynamicQuery()
.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.property("recordSetId")))
.add(RestrictionsFactoryUtil.ilike("name", courseSetName));
DynamicQuery getDdlRecordListQuery = DDLRecordLocalServiceUtil.dynamicQuery()
.add(PropertyFactoryUtil.forName("recordSetId").in(getRecordsetIdQuery));
JSONArray courseList = JSONFactoryUtil.createJSONArray();
List ddlRecordList = DDLRecordLocalServiceUtil.dynamicQuery(getDdlRecordListQuery);
if (ddlRecordList != null && ddlRecordList.size() > 0) {
int ddlRecordListSize = ddlRecordList.size();
for (int i = 0; i < ddlRecordListSize; i++) {
DDLRecord ddlRec = (DDLRecord) ddlRecordList.get(i);
Field active = ddlRec.getField("Active");
...
你能帮我一些想法吗?
答案 0 :(得分:1)
我有三个领域。在portlet中获取重复字段的解决方案。
1.LanguageName(父级和重复字段) 2. DocumentLinkLabel(重复字段) 3. DocumentLink(子字段)
for (JournalArticle journalArticle : journalArticleList) {
Document docxml;
try {
docxml = SAXReaderUtil.read(journalArticle.getContent());
Node root = docxml.getRootElement();
List<Node> languageList = root.selectNodes("/root/dynamic-
element[@name='LanguageName']");
for (int i = 0; i < languageList.size(); i++)
{
Node languageNode = languageList.get(i);
String languageName =languageNode.selectNodes("/root/dynamic-
element[@name='LanguageName']/dynamic-content[@language-
id='en_US']").get(i).getText();
System.out.println("language Name : "+ languageName);
List<Node> documentLinkLabelList =languageNode.selectNodes("dynamic-element[@name='DocumentLinkLabel']/dynamic-element[@name='DocumentLink']");
for (int j = 0; j < documentLinkLabelList.size(); j++) {
Node languageNode1 = documentLinkLabelList.get(j);
String documentLinkName =languageNode.selectNodes("dynamic-
element[@name='DocumentLinkLabel']/dynamic-content[@language-id='en_US']").get(j).getText();
System.out.println(" document Link Lable Name : "+ documentLinkName);
String linkNameList=languageNode1.selectNodes("//dynamic-
element[@name='LanguageName']["+(i+1)+"]/dynamic-
element[@name='DocumentLinkLabel']/dynamic-element[@name='DocumentLink']/dynamic-content[@language-id='en_US']").get(j).getText();
System.out.println(" linkNameList : "+ linkNameList);
}
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
您无法在代码中明确访问DDList
内容。您必须从数据库中获取记录的xml,并使用SAXParserUtil
和XPath
表达式来读取值。