Search code examples
postliferaypopupwindowliferay-7http-parameters

Liferay.Util.openWindow with a POST URL? (in order to allow longer parameters)


In my Liferay 7 JSP, I open a popup that launches a request to a Liferay portlet (that portlet transforms the text and sends the result back for display inside the popup):

<liferay-portlet:renderURL
        portletName="<%= portletId %>"
        var="uri"
        windowState="<%=LiferayWindowState.POP_UP.toString()%>">
    <portlet:param name="text" value="TEXTPLACEHOLDER" />
</liferay-portlet:renderURL>

<aui:script>
function transformTextAndShowPopup() {
    var uri = "<%= uri %>";
    uri = uri.replace("TEXTPLACEHOLDER", readTextEnteredByUser());

    javascript:Liferay.Util.openWindow({
        dialog:{
            width: 700,
            height: 300,
            resizable: true,
            modal:false,
            destroyOnClose: true
        },
        id: "My popup",
        title: "My popup",
        uri: uri
    });
</aui:script>

It works great... for short texts.

PROBLEM: I now have a requirement to handle long texts as well. I can not afford to rely on GET parameters anymore, as GET parameters can not be over a few kilobytes. Trying to push the limit results in:

The server refused this request because the request URI was too long.

QUESTION: Can I launch a Liferay.Util.openWindow with a POST request? Or otherwise open a Liferay popup with a long text? (like 30 kilobytes)


Solution

  • My suggestion is to show the dialog with a loading icon as content. Then post the text via Ajax POST query to an actionURL (use either A.io.request or jQuery) and once completed you just replace the contents of the dialog window body with the results of your ajax query.