Search code examples
javascriptliferayliferay-aui

How to remove session attribute on closing pop up window in liferay?


I am displayin the data in pop up using alloy dialog.

This is the code in first jsp..

Inside search container

here the id of viewDocs button will be overriden to viewDocs regardless of the id that was given in viewDocs.jsp

In viewDocs.jsp

        <portlet:renderURL var="docListView"
        windowState="<%=LiferayWindowState.POP_UP.toString()%>">
            <portlet:param name="mvcPath"
            value="/html/emp/docList.jsp"/>
            <portlet:param name="redirect" value="<%= currentURL %>"/>
            <portlet:param name="prk" value="<%= prk %>"/>


        </portlet:renderURL>

        <aui:button name="viewDocs" id="view_<%=prk %>" cssClass="btn btn-primary btn-small" value="View Docs"    onclick="viewDetails()"></aui:button>

        <aui:script>
        function viewDetails()
        {
          AUI().use('aui-base','aui-io-plugin-deprecated','liferay-util-window',
                 'aui-dialog-iframe-deprecated',
            function(A) {
            var popUpWindow=Liferay.Util.Window.getWindow(
                {
                    dialog: {
                        destroyOnClose:true,
                        centered: true,
                        constrain2view: true,
                        modal: true,
                        resizable: false,
                        height:300,
                        width: 700
                    }
                }
                ).plug(
                        A.Plugin.DialogIframe,
                        {
                            autoLoad: true,
                            iframeCssClass: 'dialog-iframe',
                            uri:'<%=docListView.toString()%>'
                        }).render();
            popUpWindow.show();
            popUpWindow.titleNode.html("Document List");
            popUpWindow.io.start();
             });       
        }           

In docList.jsp long proposalPrk=Long.parseLong((String)request.getParameter("prk"));

//It retrives the same value of primary key on every button click

If I set the value of primary key in session How to remove that session attribute on close of pop up?


Solution

  • You can fire an Ajax call on close of the pop-up, And in the serveResource method remove that attribute from the session.

    @Override
    public void serveResource(ResourceRequest resourceRequest,
            ResourceResponse resourceResponse) throws IOException,
            PortletException {
    resourceRequest.getPortletSession().removeAttribute(arg0)
    
        super.serveResource(resourceRequest, resourceResponse);
    }