Reputation: 369
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:
==== 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.
Upvotes: 0
Views: 2573
Reputation: 1307
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.
Upvotes: 1
Reputation: 5294
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:
Upvotes: 1
Reputation: 4730
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.
Upvotes: 0
Reputation: 5455
your problem is a bit high level, but the solutions are the following techniques:
In your portlet you can react on the parameters an display whatever jsp you want.
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.
Upvotes: 0