Foren

How to use Portlet Mode correctly ?

thumbnail
Eric COQUELIN, geändert vor 8 Jahren.

How to use Portlet Mode correctly ?

Expert Beiträge: 254 Beitrittsdatum: 03.11.13 Neueste Beiträge
Dear all,

I'm using Liferay 6.2 GA4

I was used to define mvcPath variable in the renderURL/actionURL for my past projects but noticed that it is a security breach as you provide your end users with some details regarding the file structure behind the portlet. So I decided to test the portletMode.

	<liferay-portlet:renderurl varimpl="rowURL" windowstate="<%=LiferayWindowState.MAXIMIZED.toString() %>" portletmode="<%=LiferayPortletMode.ABOUT.toString() %>">
			<liferay-portlet:param name="trainingTypeId" value="<%=String.valueOf(currentTrainingType.getTrainingTypeId())%>" />
			<liferay-portlet:param name="backURL" value="<%=backURL%>" />
		</liferay-portlet:renderurl>


I display a list of items and then if the user clicks on one item, he gets details about the clicked item.

First issue I had to face is when using EDIT, it generated for me a stack trace on the dockbar (145) because PREFERENCE right was not defined. I don't understand how my portlet did influence the dockbar but the problem is repeatable.

Then, I switched to ABOUT in case it would solve the first issue. And it did. Now, I noticed another issue. Liferay caches portlet state (including portletMode) but based on what I observed not the request query parameters. As a result, if I reload the page clicking on the page link from the navigation, my portlet will remain in "ABOUT" mode but as the query parameter "trainingTypeId" is not available, I don't have the details of the clicked item. Why does Liferay caches only part of the information?

I have found out that cache can be deactivated.

<expiration-cache>900</expiration-cache>
<cache-scope>private</cache-scope>


But this is not what I'm looking for. Indeed, on the same page, I have two portlets. The first one gives the list of items (from which I can click on each item to get details) and one other to create a new item. Let's imagine I have 80 items and moved from page 1 to page 5 in the table (I use searchContainer). If I decide to add a new item, I would like to remain on page 5. That part works and I would like it continue working. But it won't if I disable the cache.

I may have not understood correctly how portletMode works and I am thinking about reusing mvcPath in order to step forward. However, I have the feeling it is not the right way. Can anyone help me?

Thank you.
thumbnail
Prakash Khanchandani, geändert vor 8 Jahren.

RE: How to use Portlet Mode correctly ?

Expert Beiträge: 329 Beitrittsdatum: 10.02.11 Neueste Beiträge
Use mvcPath or other variable, it does not have any security problems. Portlet mode is hardly used.
Liferay plugins also use mvcPath, you can check out some marketplace plugins.

With mvcPath you should not provide the file-path of the JSP or any other view technology instead just define <init-param> in your portlet.xml and give the name of the init-param instead of the full path.

Hope this helps.
thumbnail
Eric COQUELIN, geändert vor 8 Jahren.

RE: How to use Portlet Mode correctly ?

Expert Beiträge: 254 Beitrittsdatum: 03.11.13 Neueste Beiträge
Displaying path looks a security breach. The less you share with the front-end regarding back end architecture, the better it is.

I'll try using other variable. However, I don't understand why we can't take profit from portletMode as it seems a clever & clean concept.
thumbnail
Eric COQUELIN, geändert vor 8 Jahren.

RE: How to use Portlet Mode correctly ?

Expert Beiträge: 254 Beitrittsdatum: 03.11.13 Neueste Beiträge
Alternative variable works as expected.

Anyway, if someone can detail how portletMode should be used, It will be undoubtely interesting !

Thank you !
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: How to use Portlet Mode correctly ?

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
Eric COQUELIN:
I was used to define mvcPath variable in the renderURL/actionURL for my past projects but noticed that it is a security breach as you provide your end users with some details regarding the file structure behind the portlet.


Hmm, I wouldn't make that assumption.

To me the path is a logical, organizational one only. The only reason it may represent a real path is because you have the same organization structure.

But that of course is not required. On the back end you can map a->about, b->main, c->xxx, whatever you want. The back end structure is only exposed because you choose to expose it, not because exposure is mandatory.

First issue I had to face is when using EDIT, it generated for me a stack trace on the dockbar (145) because PREFERENCE right was not defined.


I would avoid trying to reuse the standard modes as they have meaning to the portal.

As to your other issues, well I'm not sure. I don't believe that 'mode' is necessarily the right path for you as the portlet modes imply something different than navigation. Mode is for things like the portlet view, edit mode (or prefs mode for Liferay), the unused help mode, etc) which represent a different state of the portlet, not a navigation to a different area.

I'm afraid that you're going to use a different approach to keep the list in sync. I've done things like this in the past so I know it's possible, just not sure a) what you have going on and b) what you've tried that isn't working.
thumbnail
Eric COQUELIN, geändert vor 8 Jahren.

RE: How to use Portlet Mode correctly ?

Expert Beiträge: 254 Beitrittsdatum: 03.11.13 Neueste Beiträge
Hi David,

I have opted for a custom variable and do not use portletMode.

In portlet.xml, I define
<init-param>
			<name>edit-page</name>
			<value>/html/training-type/edit.jsp</value>
		</init-param>


I'm using a convention where the param name finishes with "-page".

Then, all my controllers inherits from a common custom controller:

public class ProjectPortlet extends MVCPortlet {
...
protected String getPath(PortletRequest portletRequest) {
		String mvcPath = super.getPath(portletRequest);

		if (Validator.isNull(mvcPath)) {
			String page = ParamUtil.getString(portletRequest, "page");
			mvcPath = getInitParameter(page);
		}

		return mvcPath;
	}
...
}


Then, in the JSP files, I just define the renderURL/actionURL in the following way:
<liferay-portlet:renderurl varimpl="rowURL" windowstate="<%=LiferayWindowState.MAXIMIZED.toString() %>">
			<liferay-portlet:param name="trainingTypeId" value="<%=String.valueOf(currentTrainingType.getTrainingTypeId())%>" />
			<liferay-portlet:param name="page" value="edit-page" />
			<liferay-portlet:param name="backURL" value="<%=backURL%>" />
		</liferay-portlet:renderurl>


It works fine so far. And I can hide the file structure to my front end.

Thanks again to you and Prakash.
thumbnail
Olaf Kock, geändert vor 8 Jahren.

RE: How to use Portlet Mode correctly ?

Liferay Legend Beiträge: 6396 Beitrittsdatum: 23.09.08 Neueste Beiträge
On first sight it looks like a good way to do this. I've not tried it though. And you're less flexible to introduce more content. As your JSPs probably depend on portlet requests and other portal objects, it would be quite hard to get to them manually *and* trigger any meaningful information.

However, thanks for sharing your solution.