Forums de discussion

[SOLVED] Portlet's Look and Feel Overwrites Configuration

Rashidi Zin, modifié il y a 10 années.

[SOLVED] Portlet's Look and Feel Overwrites Configuration

New Member Publications: 3 Date d'inscription: 14/06/13 Publications récentes
Hello all.

I am trying to develop a portlet which allows users to specify their own settings. For this I am using DefaultConfigurationAction. Things works as expected when I tested it without any changes to Look and Feel.

However when I specify a page to be linked to (Look and Feel -> Link Portlet URL to Page) all settings entered by user are gone. Through debugging mode I found that ResourceRequest.getPreference returns empty result although I have provided values for them in the portlets.

Is there a fix for this?

Thanks in advanced for all your helps.
thumbnail
Kan Zhang, modifié il y a 10 années.

RE: Portlet's Look and Feel Overwrites Configuration

Junior Member Publications: 68 Date d'inscription: 01/12/10 Publications récentes
The resourceRequest is usually being used when serving an ajax call. Are you using the ResourceRequest.getPreference for some specific reason? If not, there is a most common way to get the portlet preferences:

PortletPreferences preferences = renderRequest.getPreferences();

String portletResource = ParamUtil.getString(request, "portletResource");

if (Validator.isNotNull(portletResource)) {
	preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}


Hope it helps.
Rashidi Zin, modifié il y a 10 années.

RE: Portlet's Look and Feel Overwrites Configuration (Réponse)

New Member Publications: 3 Date d'inscription: 14/06/13 Publications récentes
Hi Kan Zhang. Thank you for your reply.

The issue has been fixed. You are right. I am using AJAX and sorry for not mentioning it in my question. I didn't think that it was relevant. I am using the method you suggested.

However that is not the problem. The error occurred due to Liferay generating the wrong target URL. When I choose 'Link Portlet URLs to Page', I wanted the target page to be displaying information regarding the selected link. But not to perform AJAX operation.

I'm using resourceURL to generate the url for AJAX called:

<portlet:resourceurl var="ajaxResourceURL" />


With this Liferay generated the URL pointing to the target URL while what I need the current site itself. Hence when I made another AJAX called it is the target page being called and that page does not have any configurations being assigned to. Thus the error occurred.

My solution is replacing the target URL's path (ajaxResourceURL) with the current path using javascript.

var url = '&lt;%= ajaxResourceURL %&gt;';
var path = url.substring(url.lastIndexOf("/") + 1, url.indexOf("?"));
var pathname = window.location.pathname;

pathname = pathname.substring(pathname.lastIndexOf("/") + 1, pathname.length);
url = url.replace(path, pathname);


Hopefuly this will help others who face the same problem in future emoticon