Featured post

Docker setup for Liferay 7 with MySQL

Wednesday, 13 February 2013

Add / Edit Web Content through custom portlet


May be you have used it earlier but it was never so easy.

In every project we need to add/edit/delete web content from our custom portlet.
Hope it helps...


<%@page import="com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil"%>
<%@page import="com.liferay.portlet.journal.model.JournalArticle"%>
<%@page import="java.util.List"%>
<%@page import="com.liferay.portal.util.PortalUtil"%>
<%@page import="com.liferay.portal.util.PortletKeys"%>
<%@page import="javax.portlet.WindowState"%>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="liferay-portlet" uri="http://liferay.com/tld/portlet" %>
<%@ taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>

<portlet:defineObjects />
<liferay-theme:defineObjects />
This is the <b>Add Web Content</b> portlet.

// Add Web Content Link

<liferay-portlet:renderURL windowState="<%= WindowState.MAXIMIZED.toString() %>" var="addArticleURL" portletName="<%= PortletKeys.JOURNAL %>">
<portlet:param name="struts_action" value="/journal/edit_article" />
<portlet:param name="redirect" value="<%= PortalUtil.getCurrentURL(renderRequest) %>" />
<portlet:param name="portletResource" value="<%= portletDisplay.getId() %>" />
<portlet:param name="groupId" value="<%= String.valueOf(scopeGroupId) %>" />

<liferay-ui:icon image="add_article" message="add-web-content" url="<%= addArticleURL %>" />

   List<JournalArticle> listJournalartArticles=JournalArticleLocalServiceUtil.getArticles(scopeGroupId);
   for(JournalArticle journal:listJournalartArticles){

// Edit Web Content Link

<liferay-portlet:renderURL windowState="<%= WindowState.MAXIMIZED.toString() %>" var="editURL" portletName="<%= PortletKeys.JOURNAL %>">
        <portlet:param name="struts_action" value="/journal/edit_article" />
        <portlet:param name="redirect" value="<%= PortalUtil.getCurrentURL(renderRequest) %>" />
        <portlet:param name="originalRedirect" value="<%= PortalUtil.getCurrentURL(renderRequest) %>" />
        <portlet:param name="groupId" value="<%=String.valueOf(scopeGroupId)%>" />
        <portlet:param name="articleId" value="<%=journal.getArticleId()%>" />
        <portlet:param name="version" value="<%=String.valueOf(journal.getVersion())%>" />
<liferay-ui:icon image="edit" message="edit-web-content" url="<%= editURL %>" />

<liferay-ui:journal-article articleId="<%=journal.getArticleId()%>" groupId="<%=scopeGroupId%>" />



With help of above code you can add/edit web content. It will redirect you on same portlet after adding/editing portlet.

You need to make some changes in above code which i used to display  list of web contents so you can get unique one.

Note: If there is a hyphen(-) in your portlet name then it will through an exception in second deployment.
           Either create portlet without hyphen(-) or follow this link to resolve this issue and have hyphens.

You are just done, Try & Enjoy the function.............:))


  1. Very good! Helped me a lot! Thanks!

  2. Is it possible to use another renderURL to delete a web content?

    I tried to add two params (cmd=DELETE and deleteArticleIds=journal.getArticleId()) but that doesn't work..

    Do you have any idea?

    1. I found a solution, using the same patern:

  3. Yes it is too easy to write your own url. Write a simple render of your portlet and pass article id and use journallocalserviceutil to delete article.
    Even I did the same.

  4. Thanks Very useful :)

  5. I think this is among the most significant info foor me.
    And i am glad reading your article. But wanmt to remark oon some general things, The website style is great, the
    artidles is really nice : D. Good job, cheers

    Feel free to visit my web-site :: bluehost review

  6. This is what i was looking for..nice article.
    do you know how to achieve same scenario for add subcategory functionality for my custom portlet?

    pls help

  7. It will redirect you on same portlet after adding/editing portlet.learn web deisgn

  8. Never to worry regarding the same, there are ample numbers of content writing training institute online, just head for either of them.spin rewriter review

  9. This comment has been removed by the author.

  10. The blog is great. Basically love the way how all the composed function has been put.
    e-commerce website

  11. While making a plan on the website designing, you also need to think about the theme of the whole website.https://edkentmedia.com/website-design-toronto

  12. Good post. I learn something totally new and challenging on sites I stumbleupon every day. It's always helpful to read through content from other authors and use a little something from their sites. yahoo sign in

  13. This particular tools are extremely important to me whenever I require because they help me get the practical analysis of my project completed.
    software development company in delhi