Search code examples
liferayliferay-6liferay-themeliferay-ideliferay-aui

Passing json data from one jsp to another in Liferay


I am new to liferay and ended up failing to send data from one jsp to other. Below is my use case.

  1. I have created 2 JSP files: first.jsp and second.jsp
  2. I have created a href in first.jsp and on clicking of that, I am loading second.jsp by calling a renderURL.
  3. All I want to achieve is that I am constructing a JSON data in first.jsp and when I click the href tag, I need to pass this json data to second.jsp file.

Any pointers on how to achieve this task would be appreciated?

Thanks.


Solution

  • I was able to send the data by creating a renderURL in javascript code as show below. Posting it so that it might help someone like me out there :)

    In first.jsp:-

    <script>
    AUI().ready('liferay-portlet-url', function(A) {
                     var renderURL = Liferay.PortletURL.createRenderURL();
                     renderURL.setParameter("jspPage","/html/testsample/testsamplepage.jsp");
                     renderURL.setPortletId("testsamplepage_WAR_testsamplepageportlet");
                     renderURL.setParameter("rowData",data);
                     window.location.href = renderURL;
    </script>
    

    Then in second.jsp:-

    <%
    System.out.println(request.getParameter("rowData"));
    %>