Tuesday, October 23, 2012

Liferay: dynamic data lists record actions

I'm still working with Liferay 6.1, and more specific their dynamic data lists. A question I've encountered a lot, and just ran into, is how to display the action buttons of a record in a custom list template. I haven't found the answer online, so I started to try some things myself.

 I figured the solution would be a lot like in my previous post: using the generated URL. I again switched back to the default list view, and copied the URL for the 'Edit' action. Stripping it down, this is the result:
/your_page?p_p_id=169_INSTANCE_ToH96dipcgdr&struts_action=%2Fdynamic_data_list_display%2Fedit_record&cmd=update&redirect=%2Fyour_page&recordId=$record.getRecordId()
Notice the p_p_id is copied from the URL (you can also get it from the $request), while the record id is dynamically fetched from the resultset's current record. Another important parameter is redirect. Provide it with the URL of the page you're going to display your list on. It will make sure the user will return to that page after saving or canceling the edit action. If you forget this, the user is stuck on the edit page.

3 comments:

  1. How can i get the p_p_id from the $request?

    Thank you

    ReplyDelete
    Replies
    1. Hi,

      I believe you can do

      $request.getAttribute("PORTLET_ID");

      I can't test this at the moment, though, so please let me know if it works!

      Delete
    2. I found a solution with Velocity:

      #set($portletid = $request.get("attributes").get('PORTLET_ID'))

      Do you know how I can add the delete button?

      thanks for your answer :-)

      Delete