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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14266725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 15:41:32  来源:igfitidea点击:

PortletURL to open another portlet in pop-up

javapopupliferay

提问by Any

I have a hook for create_account.jsp. In this jsp I have a javascript code where I try to open a portlet in an iframe pop-up or some pop-up from Liferay.

我有一个钩子create_account.jsp。在这个 jsp 中,我有一个 javascript 代码,我尝试在 iframe 弹出窗口或 Liferay 的某个弹出窗口中打开一个 portlet。

The question is:
How to give the portlet URL?
How can I access it?
In that portlet I only want to ask a question with YES or NO, and based on the user answer, redirect to some other page.

问题是:
如何给出portlet URL?
我怎样才能访问它?
在那个 portlet 中,我只想用 YES 或 NO 提出一个问题,并根据用户的回答重定向到其他页面。

回答by Prakash K

  1. To create a URL, you can either use <portlet:renderURL>or <liferay-portlet:renderURL>

    <liferay-portlet:renderURL
        var="testPopupURL"
        portletName="testPopup_WAR_testPopupportlet"
        windowState="<%=LiferayWindowState.POP_UP.toString() %>">
        <liferay-portlet:param name="paramToPopup" value="customParameterToThePortlet" />
    </liferay-portlet:renderURL>
    

    portletName="testPopup_WAR_testPopupportlet"this is the portletId of the portlet which you want to open.

    windowState="<%=LiferayWindowState.POP_UP.toString() %>"This is important to just show the portlet in the pop-up, or else it would open the full liferay pages with navigation and all.

  2. The javascript which you can write in your JSP to use the above URL and open the popup and the portlet within:

    // this is one of creating function
    function <portlet:namespace />showPopup(url) {
    
        var url = url;
    
        // this is one way of calling a pop-up in liferay
        // this way is specific to liferay
        Liferay.Util.openWindow(
                {
                    dialog: {
                        cache: false,
                        width:800,
                        modal: true
                    },
                    id: 'testPopupIdUnique',                
                    uri: url
                }
            );
        }
    
    // this is another way of creating a function in liferay
    Liferay.provide(
            window,
            '<portlet:namespace />showAUIPopUP',
            function(url) {
                var A = AUI();
    
                // this is another way of calling a iframe pop-up
                // this way is not specific to liferay
                popupDialog = new A.Dialog(
                    {
                        id: 'testPopupIdUnique',
                        centered: true,
                        draggable: true,
                        resizable: true,
                        width: 800,
                        stack: true
                    }
                ).plug(
                    A.Plugin.DialogIframe,
                    {
                        uri: url,
                        iframeCssClass: 'ogilvy-dialog-iframe'
                    }
                );
    
                popupDialog.render();
            },
        ['aui-dialog','aui-dialog-iframe']
    );
    
  3. You can simply call these javascript functions something like this:

    <a href="javascript: <portlet:namespace />showPopup('<%=testPopupURL%>')">
        Popup using Liferay open-window
    </a>
    
    <a href="javascript: <portlet:namespace />showAUIPopUP('<%=testPopupURL%>')">
        Pop-up using Alloy UI dialog
    </a>
    
  4. The portlet which would be displayed inside the iframeof the pop-up either should have <add-default-resource>true</add-default-resource>in liferay-portlet.xmlas:

    <portlet>
        <portlet-name>testPopup</portlet-name>
        <icon>/icon.png</icon>
        <instanceable>false</instanceable>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
        <css-class-wrapper>testPopup-portlet</css-class-wrapper>
        <!-- This property is necessary otherwise you would see a "Access denied for portlet" message when you try to open this portlet dynamically -->
        <add-default-resource>true</add-default-resource>
    </portlet>
    
  5. Or should have the property portlet.add.default.resource.check.whitelistin portal-ext.propertiesas:

    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
    
  1. 要创建 URL,您可以使用<portlet:renderURL><liferay-portlet:renderURL>

    <liferay-portlet:renderURL
        var="testPopupURL"
        portletName="testPopup_WAR_testPopupportlet"
        windowState="<%=LiferayWindowState.POP_UP.toString() %>">
        <liferay-portlet:param name="paramToPopup" value="customParameterToThePortlet" />
    </liferay-portlet:renderURL>
    

    portletName="testPopup_WAR_testPopupportlet"这是您要打开的 portlet 的 portletId。

    windowState="<%=LiferayWindowState.POP_UP.toString() %>"这对于在弹出窗口中仅显示 portlet 很重要,否则它将打开带有导航和所有内容的完整 Liferay 页面。

  2. 您可以在 JSP 中编写的 javascript 使用上述 URL 并在其中打开弹出窗口和 portlet:

    // this is one of creating function
    function <portlet:namespace />showPopup(url) {
    
        var url = url;
    
        // this is one way of calling a pop-up in liferay
        // this way is specific to liferay
        Liferay.Util.openWindow(
                {
                    dialog: {
                        cache: false,
                        width:800,
                        modal: true
                    },
                    id: 'testPopupIdUnique',                
                    uri: url
                }
            );
        }
    
    // this is another way of creating a function in liferay
    Liferay.provide(
            window,
            '<portlet:namespace />showAUIPopUP',
            function(url) {
                var A = AUI();
    
                // this is another way of calling a iframe pop-up
                // this way is not specific to liferay
                popupDialog = new A.Dialog(
                    {
                        id: 'testPopupIdUnique',
                        centered: true,
                        draggable: true,
                        resizable: true,
                        width: 800,
                        stack: true
                    }
                ).plug(
                    A.Plugin.DialogIframe,
                    {
                        uri: url,
                        iframeCssClass: 'ogilvy-dialog-iframe'
                    }
                );
    
                popupDialog.render();
            },
        ['aui-dialog','aui-dialog-iframe']
    );
    
  3. 您可以简单地调用这些 javascript 函数,如下所示:

    <a href="javascript: <portlet:namespace />showPopup('<%=testPopupURL%>')">
        Popup using Liferay open-window
    </a>
    
    <a href="javascript: <portlet:namespace />showAUIPopUP('<%=testPopupURL%>')">
        Pop-up using Alloy UI dialog
    </a>
    
  4. 这将里面显示该portletiframe的弹出式或者应该<add-default-resource>true</add-default-resource>liferay-portlet.xml如下:

    <portlet>
        <portlet-name>testPopup</portlet-name>
        <icon>/icon.png</icon>
        <instanceable>false</instanceable>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
        <css-class-wrapper>testPopup-portlet</css-class-wrapper>
        <!-- This property is necessary otherwise you would see a "Access denied for portlet" message when you try to open this portlet dynamically -->
        <add-default-resource>true</add-default-resource>
    </portlet>
    
  5. 还是应该具备的使用性能portlet.add.default.resource.check.whitelistportal-ext.properties为:

    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
    

To check out this code in action you can download 2 portlets from and refer to the instructions in this liferay forum.

要查看此代码的实际运行效果,您可以从Liferay 论坛下载 2 个 portlet 并参考其中的说明。

Hope this helps in understanding liferay better.

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

回答by grandv22

You can use the renderURL tag. In the JSP just put a form and make the treatemnet you want with your MVCPortlet Class.

您可以使用 renderURL 标记。在 JSP 中,只需放置一个表单并使用 MVCPortlet 类制作您想要的治疗网络。

<portlet:renderURL var="myPopuURL"windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
    <portlet:param name="mvcPath" value="/myJspWithYesOrNo.jsp" />
</portlet:renderURL>

<script>
   my_function_to_open_popup_with_url('<%=myPopuURL%>');
</sricpt>

Note that Liferay provides a way to create popup with AUI: http://www.liferay.com/community/liferay-projects/alloy-ui/demo?title=community-liferay-projects-alloy-ui-demos-dialog

请注意,Liferay 提供了一种使用 AUI 创建弹出窗口的方法:http: //www.liferay.com/community/liferay-projects/alloy-ui/demo?title =community-liferay-projects-alloy-ui-demos-dialog