Friday 6 June 2014

Fetching Data from Web Content Display DB and showing in jsp Liferay

Here when we store some data in WebContentDisplay it will store in JournalArtical table(content column).If you want to fetch that data and to show in JSP you can use the below code

In ext.properties file you need to mention the artical name 
for ex:article.name=latest-updates(urlTitle column in JournalArtical table)

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ page import="com.liferay.portal.kernel.util.StringPool"%>
<%@ page import="com.liferay.portlet.journal.model.JournalArticle"%>
<%@ page import="com.liferay.portlet.journalcontent.util.JournalContentUtil"%>
<%@ page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@ page import="com.liferay.portlet.journal.model.*"%>
<%@ page import="com.liferay.portal.kernel.util.PropsUtil"%>
<%@ page import="com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil"%>
<%@ page import="com.liferay.portal.kernel.util.WebKeys"%>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<portlet:defineObjects />
<%
String content = StringPool.BLANK;
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
try
{
String articleName = PropsUtil.get("article.name");
JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);
String articleId = journalArticle.getArticleId();
JournalArticleDisplay articleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,"","",themeDisplay);
content = articleDisplay.getContent();
}
catch(Exception e)
{
content = PropsUtil.get("no.article.text");
}
%>
<%= content %> 

2 comments:

  1. Getting multiple errors in jsp as:
    Multiple annotations found at this line:
    - JournalArticleLocalServiceUtil cannot be
    resolved
    - JournalArticle cannot be resolved to a
    type

    ReplyDelete