Thursday, October 29, 2009

For preview without saving the article in Journal

Hi today I want to share how to implement preview without saving web-content in liferay.
Step 1:
Add following line
<input type="button" value="<liferay-ui:message key="preview" />" onClick="<portlet:namespace />previewArticleNoStructure();" />

Step 2:
write the following function

function <portlet:namespace />previewArticleNoStructure() {
document.<portlet:namespace />fm2.action = "<%= themeDisplay.getPathMain() %>/journal/view_article_content?<%= Constants.CMD %>=<%= Constants.PREVIEW %>&groupId=<%= String.valueOf(groupId) %>&articleId=<%= HttpUtil.encodeURL(articleId) %>&version=<%= version %>&languageId=" + document.<portlet:namespace />fm1.<portlet:namespace />languageId.value + "&type=" + document.<portlet:namespace />fm1.<portlet:namespace />type.value;
document.<portlet:namespace />fm2.target = "_blank";
document.<portlet:namespace />fm2.title.value = document.<portlet:namespace />fm1.<portlet:namespace />title.value;
document.<portlet:namespace />fm2.xml.value = <portlet:namespace />getArticleContentNoStructure();
document.<portlet:namespace />fm2.submit();

}

Step 3:

Write this function

function <portlet:namespace />getArticleContentNoStructure(){

var xsd = "<root available-locales=\"en_US\" default-locale=\"en_US\">";
xsd += "<static-content language-id=\"en_US\">";
xsd += "<![CDATA[";
xsd += window. xsd += "]]>";
xsd += "</static-content>";
xsd += "</root>";
return xsd;
}

that's it .
Enjoy!!!

No comments: