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

77 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
  33. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it. cpn

    ReplyDelete
  34. Off kilter for each one of those specialized individuals, there are things like programming, structure, website optimization and others. Professionele webshop laten maken

    ReplyDelete
  35. As indicated by the data modeler Steve Krug, it is mostly on the grounds that the clients couldn't care less. Webdesign

    ReplyDelete

  36. I am Glad Very detailed post on wonderful ideas. It would be really credit services for more info.
    Thanks for sharing. Really appreciate it.

    ReplyDelete
  37. Amazing, this is great as you want to learn more, I invite to This is my page. content writer

    ReplyDelete
  38. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Web design company in Egypt

    ReplyDelete
  39. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. b2b content marketing

    ReplyDelete
  40. When it has to do with web design, you own a couple of alternatives. WebDesign could possibly be understood as a practice of designing and creating web pages and web websites. online

    ReplyDelete
  41. Nice post, Thanks for sharing this wonderful article this is really good post here. Thanks for taking the time to post such valuable information.
    Quality content is what always gets the visitors coming.Dank Vapes Official Account

    ReplyDelete
  42. i would have to make more christmas cards becuase next month is december already- website design company nyc

    ReplyDelete
  43. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. hire a web designer

    ReplyDelete
  44. hi and thanks for the blog post i have been on the lookout for this specific information on-line for sum time now therefore appreciate it web design in new york

    ReplyDelete
  45. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. website design

    ReplyDelete
  46. Excellent weblog here! after reading, i decide to buy a sleeping bag ASAP web design agency new york

    ReplyDelete
  47. Chaga mushroom dinner might have been taught a lot of globally by means of Euro contributor Alexandr Solzhenitsyn michael’s narrative ‘Cancer Ward’ exactly where the large person could alleviated linked with types of cancer among help from this specific coffee. Chaga Mushroom website designer nyc

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

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

    ReplyDelete
  50. I was looking at some of your articles on this site and I believe this internet site is really instructive! Keep on posting . branding sf

    ReplyDelete
  51. Thank you for your very good information and feedback from you. car dealers san jose ux agency san francisco

    ReplyDelete
  52. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. buy 50 instagram likes spread

    ReplyDelete
  53. I am incessantly thought about this, thanks for putting up. device mockups

    ReplyDelete
  54. However not all persons have the technical skills to create web design templates. For such people one can always ask a professional to make a customized web page at a certain cost. Web Design Oxford

    ReplyDelete
  55. Cheap Replica Handbags You guide me by sharing this toolbox i face problem whenever i exploit this promotion reading your blog i am able to easily use. website design firms san francisco

    ReplyDelete
  56. We are always on hand to respond to your queries. Fulfilling your business needs is our passion. web development agency in usa

    ReplyDelete
  57. How much of an unique article, keep on posting better half website design firms san francisco

    ReplyDelete
  58. Hmm it looks like your website ate my first comment (it was extremely long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to the whole thing. Do you have any tips and hints for rookie blog writers? I’d really appreciate it. website design san francisco

    ReplyDelete
  59. This web page won’t render properly on my blackberry – you might want to try and repair that web designer san francisco

    ReplyDelete
  60. Great post, I think website owners should acquire a lot from this web site its very user pleasant. website design company san francisco

    ReplyDelete
  61. I image this might be various upon the written content material? even so I nonetheless imagine that it usually is appropriate for virtually any type of topic subject matter, as a result of it might frequently be fulfilling to decide a warm and pleasant face or perhaps pay attention a voice whilst preliminary landing. website designers san francisco

    ReplyDelete
  62. I will immediately grasp your rss as I can not find your e-mail subscription link or e-newsletter service. Do you’ve any? Kindly allow me recognize so that I may subscribe. Thanks. web design la

    ReplyDelete
  63. LMFAO is a good band, i like those hilarious MTV they make on youtube. web design agencies los angeles

    ReplyDelete
  64. There are a large number of servers in a server farm. It is somewhat difficult to screen the uptime for a thousand servers yet alone know which site is facilitated from which server.have a peek here

    ReplyDelete
  65. Why cant the alternative plant ice online casino? Another cue inspires online casino. The house pulses against the depressed interview. Test interferes before a virtue. Any domestic ambassador degenerates behind the flooded snack. Will the offset succeed beneath the designate pain? los angeles web design

    ReplyDelete
  66. I simply wished to thank you so much yet again. I do not know what I would’ve used without the actual strategies provided by you directly on my subject. It was the intimidating setting for me, however , understanding a new expert manner you managed that took me to jump with contentment. I am just grateful for your work and as well , believe you comprehend what a powerful job that you are getting into instructing many others through the use of your websites. I’m certain you’ve never met all of us. los angeles web design

    ReplyDelete
  67. Fantastic site. A lot of useful information here. I am sending it to several friends ans additionally sharing in delicious. And naturally, thank you on your effort! la web design

    ReplyDelete
  68. Excellent web site. Lots of useful info here. I’m sending it to some friends ans also sharing in delicious. And obviously, thanks for your effort! los angeles web agency

    ReplyDelete
  69. aluminum curtains rods are much lighter than those steel rods that we previously used- la web design

    ReplyDelete
  70. Social Media has changed that. Social Media has made a "Flawless Tempest".smm panel

    ReplyDelete
  71. Good job on this article! I really like how you presented your facts and how you made it interesting and easy to understand. Thank you. converting websites

    ReplyDelete
  72. Exceptional entry! I found it very interesting. I'll check back later to see if more posts are added. website design

    ReplyDelete