0

我有一个要求。我在 Web Content Display portlet 中 添加了两个文本字段Value和结构。Key具有两个字段“键”和“值”的 Web 内容

现在在 portlet 中,我从下面的硬代码中获得了价值。

BasicModel model = (BasicModel)requestContext.getFlowScope().get("BasicModel");
        if(model == null){
            model = new BasicModel();
        }
        model.setEmployeeId("AB1223344S");
        model.setHireDate("01-Jan-2000");
        model.setNiNumber("AB123456S");
        model.setDateOfBirth("12-Dec-1980");
        model.setBasicForm(new BasicDetailsForm());
    }

但我想要的valueattributeweb content. 就像,如果我在添加的 Web 内容结构字段中 给出了lfr.intel.empidaskey和as 值,就像这样。ABSD1822D键和值的新添加信息

我们可以像这样获取键的值。

model.setEmployeeId(lfr.intel.empid);
4

2 回答 2

0

您可以为此编写一个自定义函数,将密钥传递给该函数,现在该函数将使用 JournalArticleLocalServiceUtil API 从数据库中获取相应的值。

现在您需要找到如何从 JournalArticleLocalServiceUtil 中获取值,您可以使用 google 或链接来帮助您。

谢谢。

于 2015-09-09T13:12:02.283 回答
0

试试这个,假设你可以得到JournalArticle对象,我已经使用resourcePrimKey

long resourcePrimKey = 12345; //hard coded the resourcePrimKey
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey);
com.liferay.portal.kernel.xml.Document document = SAXReaderUtil.read(article.getContentByLocale("en_US"));

Node keyNode = document.selectSingleNode("/root/dynamic-element[@name='Key']/dynamic-content");
String key = keyNode.getStringValue();

Node valueNode = document.selectSingleNode("/root/dynamic-element[@name='Value']/dynamic-content");
String value = valueNode .getStringValue();
于 2016-06-03T05:00:19.333 回答