Sunday, October 26, 2014

Sample popup in Liferay 6.2 with close button

Hello! To start with this blog I will publish the code for a liferay 6.2 popup.

Liferay 6.2 uses the new AUI 2.0 version. When this versión of Liferay was developed some AUI old modules became deprecated.





The following is sample code for a Liferay 6.2 popup with a close button.

Portlet view jsp code:

<aui:script>

function showPopup() {
AUI().use( 'aui-io',
'aui-dialog',
function(A) {

Liferay.Util.openWindow(
           {
                dialog: {
                   centered: true,
     destroyOnClose: true,
                    cache: false,
                    width: 500,
                   height: 300,
                    modal: true
               },
               title: 'Sample Popup',
                   id:'<portlet:namespace/>popUpDialog',            
               uri:'<%=dialogUrl.toString()%>'
            });
           
           
            Liferay.provide(
                   window,
                   '<portlet:namespace/>closePopup',
                   function(popupIdToClose) {
                   var popupDialog = Liferay.Util.Window.getById(popupIdToClose);
                   popupDialog.destroy();
                   },
                   ['liferay-util-window']
              );

});
}



</aui:script>

<div>
<h1>AUI Popup</h1><br/>
<aui:button id="dialogButton" value="Show popup" onClick="showPopup();"> </aui:button>
</div>


Popup jsp code:


<portlet:actionURL name="helloFunction" var="helloFunctionUrl">
<portlet:param name="mvcPath" value="/popup.jsp"/>
</portlet:actionURL>


<aui:script>
    function closeThis(){
        Liferay.Util.getOpener().<portlet:namespace />closePopup('<portlet:namespace />popUpDialog');
    }
</aui:script>


<form name="<portlet:namespace/>fm" action="<%=helloFunctionUrl%>" method="post">

<h1>Sample popup</h1>

<aui:button type="submit" value="Call function" />
<aui:button name="close" value="close" onClick="closeThis();"/>

 </form>


Portlet class code:

public class SimplePortlet extends MVCPortlet{

@Override
public void init() throws PortletException {
super.init();

copyRequestParameters = true;
}

public void helloFunction(ActionRequest actionRequest, ActionResponse actionResponse)throws Exception {
 System.out.println("Hello!!");
   }

}

2 comments: