Liferay version : 6.1.20EE

To get List of journal Article filter by Tags use the below code.



public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest
.getAttribute(WebKeys.THEME_DISPLAY);
try {
List<JournalArticle> journalArticles = getArticleByTags(themeDisplay.getScopeGroupId(), "help");
renderRequest.setAttribute("journalArticles", journalArticles);
} catch (SystemException e) {
e.getMessage();
} catch (PortalException e) {
e.getMessage();
}

public List<JournalArticle> getArticleByTags(long groupId, String tagName)
throws PortalException, SystemException {

AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

long[] anyTagIds = AssetTagLocalServiceUtil.getTagIds(groupId, new String[] { "alllocation", tagName });
assetEntryQuery.setAnyTagIds(anyTagIds);

List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
List<JournalArticle> journalArticleList = new ArrayList<JournalArticle>();

for (AssetEntry ae : assetEntryList) {
JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK());
JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(groupId, journalArticleResourceObj.getArticleId());
journalArticleList.add(journalArticleObj);
}

return journalArticleList;
}


In jsp file add this below code


<%
List journalArticles =(List) renderRequest.getAttribute("journalArticles");
for(JournalArticle journalArticle : journalArticles){
%>
<%=journalArticle.getTitle("en_US") %>
<%
}
%>

Advertisements

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 )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: