2013-01-10 11 views
6

Ho un gancio per create_account.jsp. In questo jsp ho un codice javascript in cui provo ad aprire un portlet in un pop-up iframe o in alcuni pop-up di Liferay.PortletURL per aprire un altro portlet in pop-up

La domanda è:
Come fornire l'URL del portlet?
Come posso accedervi?
In questo portlet voglio solo fare una domanda con SÌ o NO, e in base alla risposta dell'utente, reindirizzare ad un'altra pagina.

risposta

2

È possibile utilizzare il tag renderURL. Nel JSP basta inserire un modulo e creare il treatemnet desiderato con la classe 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> 

Nota che Liferay fornisce un modo per creare popup con AUI: http://www.liferay.com/community/liferay-projects/alloy-ui/demo?title=community-liferay-projects-alloy-ui-demos-dialog

9
  1. per creare un URL, è possibile utilizzare <portlet:renderURL> o <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" questo è il portletId del portlet che desideri aprire.

    windowState="<%=LiferayWindowState.POP_UP.toString() %>" Questo è importante per mostrare solo il portlet nel pop-up, o altrimenti sarebbe aprire le pagine Liferay completi con navigazione e tutti.

  2. Il javascript cui è possibile scrivere nel vostro JSP per utilizzare l'URL sopra e aprire il pop-up e il portlet entro:

    // 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. Si può semplicemente chiamare questi javascript funzioni o meno così:

    <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. il portlet che verrebbe visualizzato all'interno della iframe del pop-up o dovrebbe avere <add-default-resource>true</add-default-resource> in liferay-portlet.xml come:

    <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. o dovrebbe avere la proprietà portlet.add.default.resource.check.whitelist in portal-ext.properties come:

    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 
    

per vedere questo codice in azione è possibile scaricare 2 portlet da e fare riferimento alle istruzioni in this liferay forum.

Spero che questo aiuti a comprendere meglio liferay.