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

  14. Hmm… I interpret blogs on a analogous issue, however i never visited your blog. I added it to populars also i’ll be your faithful primer.
    mason soiza

  15. This is where the web designer is advising us about the very product they sell. We may never get clear information about what all our choices are.vizitini┼│ korteli┼│ maketavimas

  16. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work relojes personalizados con nombre

  17. The web contains many energizing impacts so when you begin pondering your site it's simple for your psyche to stray into a universe of visual livelinesss and gaudy gadgets. Webdesign

  18. Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also Webdesign bureau

  19. I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site. Web Design Toronto

  20. Wow, this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it. weebly cost

  21. Here are a few highlights that can truly damage the over all idea of your website composition. It is critical to pay heed to the most widely recognized mix-ups website specialists submit. Web Design Curriculum

  22. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! freelance web designer peter

  23. If you are looking for more information about flat rate locksmith Las Vegas check that right away. Web Designing

  24. When a mobile user changes from landscape to portrait mode, the intuitive design will ensure the page gets bigger or smaller. Furthermore, each element, be it an image, textbox or video will also resize itself to correspond with the different dimensions.Rourkela

  25. Damn that is great I need to arrive sometime in the not so distant future.Webdesign

  26. This attitude on the other hand ought to persist with the webmasters too. Many clients have a set mind that just browsing through the websites qualifies the webmasters to make design decisions. Webdesign

  27. Generally web designs comprises of innovated and graphical techniques as well as they are created to become easy approachable to the web searchers and it is done using wide understandable techniques.optimize up

  28. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. web design agency lakeland