【问题标题】:Getting value of key from Web Content Display Portlet从 Web Content Display Portlet 获取键值
【发布时间】:2015-09-09 07:19:49
【问题描述】:

我有一个要求。我从 Web Content Display portlet 的结构中添加了两个文本字段 ValueKey

现在在 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());
    }

但我想要的是从web content 获取每个attributevalue。就像,如果我在添加的 Web 内容结构字段中将 lfr.intel.empid 作为 keyABSD1822D 作为值。

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

model.setEmployeeId(lfr.intel.empid);

【问题讨论】:

  • 你为什么在这里使用我们的内容?你能详细说明你的要求吗
  • @PankajkumarKathiriya 如果可以的话,我会满足老年人的要求。

标签: liferay liferay-6 liferay-6.2


【解决方案1】:

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

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

谢谢。

【讨论】:

  • 我们是否必须在我的 portal-ext.properties 文件中添加任何属性?
  • 没有。 BDW 为什么要在属性文件中添加条目?
【解决方案2】:

试试这个,假设你可以得到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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多