How to display journal content inside a portlet

Sometimes you want a portlet contains some texts from journal article, so user can easily edit the text. In that case you have to modify the presentation file of your portlet ( whether it’s a JSP file, VM, etc ), to display the content. You can use com.liferay.portlet.journalcontent.util.JournalContentUtil class to display the content. Assume that you use JSP for your presentation and you use ext environment for your portlet, here are the steps to do it :

  1. Include /html/portlet/init.jsp on your portlet’s JSP.
  2. Include com.liferay.portlet.journalcontent.util.JournalContentUtil in your JSP file
  3. Get your journal article’s id
  4. Call getContent method of JournalContentUtil inside the JSP

Let’s go to the details.

Include /html/portlet/init.jsp on your portlet’s JSP like this :


<%@ include file="/html/portlet/init.jsp" %>

Include JournalContentUtil on your JSP file, like this

<%@ page import="com.liferay.portlet.journalcontent.util.JournalContentUtil" %>

Create your journal article, after you save your article, Liferay will generate an id for your article. Take note of this id, so we can use on our method call as argument later in our JSP page.

Now on your portlet’s JSP, create a code like this

<div id="journal-article-import" >		  
<%
  String articleId =  "13734";  // this is Journal Article's Id
  String languageId = LanguageUtil.getLanguageId( renderRequest );
  String content = JournalContentUtil.getContent(  themeDisplay.getPortletGroupId(), articleId, languageId, themeDisplay);
%>
<%= content %>  
</div>

themeDisplay is implicit variable inside page context, that is set using Liferay's custom tag ;.

The definition of this custom tag can be seen on liferay-theme.tld. Here is the related content of liferay-theme.tld


	<tag>
		<name>defineObjects</name>
		<tag-class>com.liferay.taglib.theme.DefineObjectsTag</tag-class>
		<tei-class>com.liferay.taglib.theme.DefineObjectsTei</tei-class>
		<body-content>empty</body-content>
	</tag>

So if you want to find out what are other implicit variables that was set whenever you include /html/portlet/init.jsp, you can take a look at com.liferay.taglib.theme.DefineObjectsTag class.

Done. Tested on Liferay 5.1.1

1 comment so far

  1. Andrés Torres on

    hi! is there any way to do the same in a portlet create in SDK enviroment instead EXT enviroment?

    Thanks in advance


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: