java – PortletURL在弹出窗口中打开另一个portlet

前端之家收集整理的这篇文章主要介绍了java – PortletURL在弹出窗口中打开另一个portlet前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个create_account.jsp的钩子.
在这个jsp我有一个 javascript代码,我尝试在iframe弹出窗口或Liferay的一些弹出窗口中打开一个portlet.

问题是:
如何提供portlet URL?
我该如何访问它?
在该portlet中,我只想问一个YES或NO的问题,并根据用户的答案,重定向到其他页面.

解决方法

>要创建URL,您可以使用< portlet:renderURL>或者< liferay-portlet:renderURL>
  1. <liferay-portlet:renderURL
  2. var="testPopupURL"
  3. portletName="testPopup_WAR_testPopupportlet"
  4. windowState="<%=LiferayWindowState.POP_UP.toString() %>">
  5. <liferay-portlet:param name="paramToPopup" value="customParameterToThePortlet" />
  6. </liferay-portlet:renderURL>

portletName =“testPopup_WAR_testPopupportlet”这是您要打开的portlet的portletId.

windowState =“<%= LiferayWindowState.POP_UP.toString()%>”这对于在弹出窗口中显示portlet非常重要,否则它将打开带有导航和所有内容的完整liferay页面.
>您可以在JSP中编写以使用上述URL并在其中打开弹出窗口和portlet的javascript:

  1. // this is one of creating function
  2. function <portlet:namespace />showPopup(url) {
  3.  
  4. var url = url;
  5.  
  6. // this is one way of calling a pop-up in liferay
  7. // this way is specific to liferay
  8. Liferay.Util.openWindow(
  9. {
  10. dialog: {
  11. cache: false,width:800,modal: true
  12. },id: 'testPopupIdUnique',uri: url
  13. }
  14. );
  15. }
  16.  
  17. // this is another way of creating a function in liferay
  18. Liferay.provide(
  19. window,'<portlet:namespace />showAUIPopUP',function(url) {
  20. var A = AUI();
  21.  
  22. // this is another way of calling a iframe pop-up
  23. // this way is not specific to liferay
  24. popupDialog = new A.Dialog(
  25. {
  26. id: 'testPopupIdUnique',centered: true,draggable: true,resizable: true,width: 800,stack: true
  27. }
  28. ).plug(
  29. A.Plugin.DialogIframe,{
  30. uri: url,iframeCssClass: 'ogilvy-dialog-iframe'
  31. }
  32. );
  33.  
  34. popupDialog.render();
  35. },['aui-dialog','aui-dialog-iframe']
  36. );

>您可以简单地将这些javascript函数称为:

  1. <a href="javascript: <portlet:namespace />showPopup('<%=testPopupURL%>')">
  2. Popup using Liferay open-window
  3. </a>
  4.  
  5. <a href="javascript: <portlet:namespace />showAUIPopUP('<%=testPopupURL%>')">
  6. Pop-up using Alloy UI dialog
  7. </a>

>将在弹出窗口的iframe内显示的portlet应该具有< add-default-resource> true< / add-default-resource>在liferay-portlet.xml中:

  1. <portlet>
  2. <portlet-name>testPopup</portlet-name>
  3. <icon>/icon.png</icon>
  4. <instanceable>false</instanceable>
  5. <header-portlet-css>/css/main.css</header-portlet-css>
  6. <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
  7. <css-class-wrapper>testPopup-portlet</css-class-wrapper>
  8. <!-- This property is necessary otherwise you would see a "Access denied for portlet" message when you try to open this portlet dynamically -->
  9. <add-default-resource>true</add-default-resource>
  10. </portlet>

>或者应该将portal-ext.properties中的属性portlet.add.default.resource.check.whitelist作为:

  1. portlet.add.default.resource.check.whitelist=3,56_INSTANCE_0000,58,82,86,87,88,103,113,145,164,166,170,177,testPopup_WAR_testPopupportlet

要查看此代码的实际操作,您可以从中下载2个portlet并参考this liferay forum中的说明.

希望这有助于更好地理解liferay.

猜你在找的Java相关文章