Search code examples
liferayportletliferay-7

How to add portlet with redirect to special jsp (edit) in Liferay


I have a portlet in liferay that shows list of items and allow to add/edit (add/save/list of items done by service builder).

Now I need separate liferay page with only add new functionality - can this be done with one portlet or should I copy it to separate portlet?

What I think I need:

  1. way to open portlet with redirection to edit form (edit.jsp)
  2. way to redirect to other liferay page with param (itemId) that would open that page on details.jsp and not standard view.jsp.

==== EDIT:

Now I do have links like that:

details:

<liferay-portlet:renderURL varImpl="rowURL">
    <portlet:param name="backURL" value="<%= portletURLString %>" />
    <portlet:param name="mvcPath" value="/html/details.jsp" />
    <portlet:param name="itemId" value="<%= String.valueOf(item.getId()) %>" />
</liferay-portlet:renderURL>

add:

<liferay-portlet:renderURL varImpl="addURL">
    <portlet:param name="mvcPath" value="/html/edit.jsp" />
</liferay-portlet:renderURL>

But they only work in the same portlet/page.

In liferay I have two public pages: "search/details" and "add".

On the "add" page this portlet should render edit.jsp (second url). Then after an action I should redirect authorized user to "search/details" page with id of the newly created item and show its details.

I can create two portlets but I'm sure there is better and more liferayish solution to this problem.


Solution

  • You could set the default view with portlet preferences / custom configuration. Your portlet, P, can have a configuration parameter for the "type" of portlet A should be (in your case you have two types, "view" and "detail"). Based on this parameter, you can handle the render / action logic accordingly.

    That way, with two layouts, L1 and L2, you can put an instance of P on L1 and set its type to "view". You can then put another instance of P on L2.

    In P's components (ex. render command) you can check the type (view or detail) and you have control here over the render / action logic as per your use cases (the jsp you want to use, etc.)

    For more information on configuration in liferay 7 see: