Featured post

Docker setup for Liferay 7 with MySQL

Wednesday, 13 February 2013

Add / Edit Web Content through custom portlet

Hi,

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-portlet:renderURL>

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

<div>
<%
   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-portlet:renderURL>
<liferay-ui:icon image="edit" message="edit-web-content" url="<%= editURL %>" />

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

</div>

-->

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.............:))

36 comments:

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

    ReplyDelete
  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?

    ReplyDelete
    Replies
    1. I found a solution, using the same patern:
      http://pastebin.com/iHyz6jJg

      Delete
  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.

    ReplyDelete
  4. Thanks Very useful :)

    ReplyDelete
  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

    ReplyDelete
  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
    thanks

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

    ReplyDelete
  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

    ReplyDelete
  9. This comment has been removed by the author.

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    ReplyDelete
  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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  29. Thanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again. Reseller Hosting

    ReplyDelete
  30. This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. niche releated backlinks

    ReplyDelete
  31. Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. Anonymous Bites Back

    ReplyDelete
  32. DIY web site design offers you total control over the project and over the site that is why its simply gaining popularity. It takes the work out of dealing with consultants, designer, contractor landscaper and the likes.Top 10 Digital Marketing Agencies in Singapore

    ReplyDelete