掲示板

How to extend portlet sharing

10年前 に Julien Tabouret によって更新されました。

How to extend portlet sharing

Junior Member 投稿: 27 参加年月日: 13/05/17 最新の投稿
Hi everyone,

Before posting I've searched for informations about portlet sharing but it seems that people are only interested in disabling it. Our need is quite different because we want our users to be able to place some of our portlets on their web site. But as usual the native functionality does not match our need so we want to extend it.

By default, sharing a portlet on any website generates that kind of code snippet :

<script src="http://localhost:8080/html/js/liferay/widget.js" type="text/javascript"></script>
<script type="text/javascript">
	Liferay.Widget({ url: 'http://localhost:8080/widget/web/guest/home/-/agenda_WAR_estimagendaportlet'});
</script>


We came up with the idea of adding key/value pairs to the JSON object used as a parameter to the "Widget" method.

So before diving into the Liferay Portal code, I wonder if someone could be able to give me some informations about :
  • how the code snippet is generated by Liferay ?
  • what is the Java controller that handle the http request when the "Liferay.Widget" is called on the client side ?


Thanks you for your help.
10年前 に Julien Tabouret によって更新されました。

RE: How to extend portlet sharing

Junior Member 投稿: 27 参加年月日: 13/05/17 最新の投稿
After some research, this is what I found :

Step 1 : Generating code snippet

There is no use to change the JSON structure since it is only used by widget.js to create the URL of the <iframe>. So if you want to add members to the JSON structure, you'll have to change widget.js too. But I think that it's more simple to add parameters to the URL.

The JSP file "portal-web/docroot/html/portlet/portlet_sharing/view.jsp" is responsible for the code snippet generation but relies on the following services to get the widget URL:

Portlet portlet = PortletLocalServiceUtil.getPortletById(company.getCompanyId(), portletId);
String widgetURL = PortalUtil.getWidgetURL(portlet, themeDisplay);


As described in the Manning book, the portlet ID of a custom portlets is the portlet-name with "_WAR_<name_of_war>" appended to.

Step 2 : Serve request

The controller associated with the /widget servlet is /portal-impl/src/com.liferay.portal.servlet/WidgetServlet.java. It extracts the extra path info and dispatches the request.

Since the extra path info always starts with /web, the controller handling the request this time is /portal-impl/src/com.liferay.portal.servlet.FriendlyURLServlet.java. Once again the request is dispacthed to a new URL that you can find easily by setting the "com.liferay.portal.servlet.FriendlyURLServlet" log level to "DEBUG".

In my case, the initial "/widget/web/guest/home/-/11" path has become "/c/portal/layout?p_l_id=10182&p_v_l_s_g_id=0&p_p_state=maximized&p_p_lifecycle=0&p_p_id=11&p_p_mode=view". The "p_p_id" id the portlet ID. The "p_v_l_s_g_id" is the virtual layout ID - I don't know what is a virtual layout but I guess it just tells the server to send only the portlet, not the whole page.

Step 3 : Conclusion

Customizing the sharing concept of Liferay is not necessary since it takes care of the "technical stuffs". All we need to do is to add the URL params that we need. Liferay wiil gently pass them to our MVCPortlet controller.
thumbnail
9年前 に James Stuart Milne によって更新されました。

RE: How to extend portlet sharing

New Member 投稿: 11 参加年月日: 10/02/23 最新の投稿
Great Post, this is what i was looking for, however i would like to add a couple of custom javascript files in the sharing box. Do you know where i should modify?

Best regards
8年前 に Julien Tabouret によって更新されました。

RE: How to extend portlet sharing

Junior Member 投稿: 27 参加年月日: 13/05/17 最新の投稿
Hello James,

Sorry for the delay.
I think the best choice is to hook the JSP file "portal-web/docroot/html/portlet/portlet_sharing/view.jsp" so you can add your custom JS files.
Please tell me how you implemented it.

Best regards.