Pages

Hot News

Showing posts with label Webcontent. Show all posts
Showing posts with label Webcontent. Show all posts

Saturday, 19 April 2014

Display Webcontent in JSP?

Hi guys,

There are many way to display webcontent in jsp.
Here, I am explaining  two easiest way.

First Way :
If you are thinking to display web content in JSP page, Its only 2 steps you follow as given below :


Step 1.

Put Below configuration in " portal-ext.properties " :

article.name=YourJournalArticleName
no.actical.text=No Article Exists with this name.

Step 2.
Put Below code inside your jsp.
JSP File : 

<%
String content = StringPool.BLANK;
try{ 
String articleName = PropsUtil.get("article.name");

JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);
String articleId = journalArticle.getArticleId(); 
JournalArticleDisplay articleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScoprGroupId(), articleId,"","",themeDisplay);
content = articleDisplay.getContent();
}Catch(Exception e){
content = PropsUtil.get("no.article.text");
}
%>

<%= content %>

*Note: In this way you required to restart server because we have updated portal-ext.properties file.

 ----------------------------------------------------------------------------------------------------------------------------------

Alternate cool option to display webcontent in jsp as:

Follow the list of below steps.
Step 1:

Put below code inside your java class.
For retrieve the wecontentid  and  GroupId.

 long lGroupId = themeDisplay.getScopeGroupId();
String lGroupName = themeDisplay.getScopeGroupName();


JournalArticle jArticleId = JournalArticleLocalServiceUtil.getArticleByUrlTitle(

lGroupId, "webcontentname");

renderReq.setAttribute("lGroupId", lGroupId);
renderReq.setAttribute("jArticleId", jArticleId.getArticleId());

Step 2:

Put below code inside your jsp.


<liferay-ui:journal-article articleId="${jArticleId}"

groupId="${lGroupId}" />

*Note: If we are follow the above way then we don't required to restart the server.

That's all !!

Let me know if u have any suggestions/queries, I would like to hear from your side.