0
votes

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.

4
You can achieve this using single (same) portlet on multiple pages. Just set target="_blank" on the anchor(s), where you are using rowURL / addURL to open that link on new tab. The rest will be handled by portlet lifecycle to render specific view based on the portlet:param set for the URL.Parkash Kumar
Having different configurable entrypoint JPSs for you portlet, sounds like setting PortletPreferences (Portlet Edit-Mode) for your portlet instance and use this in your custom doView/RenderCommand implementation. Other Solution: Maybe using a Liferay popup also solves your issues AUI Popup UseDialog? Just replace the mvcPath of the first example snippet.Andre Albert

4 Answers

1
votes

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:

1
votes

if you have a static layout of your site and you know what portlet will be placed where you can use the plid (page layout ID) parameter of the liferay-renderurl tag. That allows you to not only address portlets but also pages. The plid is usually loaded from some configuration.

Another trick how to reuse the existing code is to reuse the actual form and action classes and create only new portlet definitions. This expects that you use Liferay MVC + action command pattern.

0
votes

your problem is a bit high level, but the solutions are the following techniques:

  1. You can define a friendly URL for your portlet which will transfer the parameters directly in your portlet.

In your portlet you can react on the parameters an display whatever jsp you want.

  1. If you defined the friendly url from 2. you can use it within a link easily:

    <a href="/my-form-page/-/my-param1/my-param2">Edit</a>

If you can provide a bit of example code we can go more into detail.

0
votes

No hard-n-fast rule to create separate portlets for view / add / update actions. That totally depends on you.

You can achieve this using single (same) portlet on multiple pages, which default to listing view. Just set target="_blank" on the anchor(s) of the listing view for rowURL and addURL actions to open that link on new tab. The rest will be handled by portlet lifecycle to render specific view based on the portlet:param set for the URL.

The other way around can be the plain redirection to page with itemId=abc and action=add/update as queryString. and in doView of your portlet get that parameter from request and based on those parameters, filter inclusion of jsp.