Wednesday 27 June 2012

Display journal article in to the custom.jsp

Some time we need to display journal article into our custom jsp not from the web content display portlet.

Following is the code snippet for fetching the journal article and display it into the custom.jsp

1)Code for the controller of the portlet.
JournalArticle article = null;
JournalArticleDisplay display = null;

article = JournalArticleLocalServiceUtil.getArticleByUrlTitle(themedisplay.getScopeGroupId(), formatUrlTitle(name));

Function for getting the formatted url title.

private String formatUrlTitle(String name){
        return name.toLowerCase().replaceAll(" ","-");
    }

Then get the journal article display object  for the journal article

display = JournalArticleLocalServiceUtil.getArticleDisplay(themedisplay.getScopeGroupId(),article.getArticleId(),WebKeys.WINDOW_STATE,themedisplay.getLanguageId(),themedisplay);

set the article display object
request.setAttribute("post_of_the_week", article);



On the jsp side.

<%
JournalArticleDisplay display = (JournalArticleDisplay)renderRequest.getAttribute("post_of_the_week");

%>

<%=display.getContent() %>



1 comment: