6

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

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

4

2 回答 2

9
  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. iframe将在弹出窗口<add-default-resource>true</add-default-resource>中显示的 portlet应该具有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
    

要查看此代码的运行情况,您可以从该 liferay 论坛下载 2 个 portlet 并参考说明。

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

于 2013-01-11T13:28:05.993 回答
2

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

<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>

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

于 2013-01-11T05:40:09.217 回答