1
votes

I am using java liferay portal, in which there are multiple portlets. I want to create a portlet with a form that when it is submitted the data is retrieved and the specific result is shown in some other page portlet. But unfortunately these things are not going in the way.

I was thinking of using sessions but 2 problems arrised.

  1. javascript value assignment to java variable.
  2. if the values are passed to the page on which the specific portlet is placed, that portlet doesn't get the values.

Then I heard the concept of Inter Portlet Communication(IPC), and took some help from "liferay in action" but there the code works if both the portlets are placed on the same page, and my requirement is that one portlet is placed on first page and when the form is submitted it is redirected to the second page, to the second portlet for getting the parameters. I tried more example but its not working in my way.

3

3 Answers

1
votes

I have found another way of, a relatively easiest, just tried that wiki from liferay

1
votes

As i understood, you have some JavaScript parameters which you want to pass to the next page. You can, though, do it with APPLICATION_SCOPE of PortletSession and you can solve the problem of converting JS params to Java by placing the values in a input. If these input vars aren't supposed to be written by the user and you take them from somewhere else, you can make the input hidden:

In your jsp:

<form>
 <input type="hidden" id="myinput1" name="in1" value="">
 <input type="hidden" id="myinput1" name="in2" value="">
</form>

<script>
var a = "avalue";
var b = "bvalue";
document.getElementById("myinput1").value=a;
document.getElementById("myinput2").value=b;
</script>

Then submit the form when you need to. Next, you'll be able to do like this in the ProcessAction method of the portlet:

String a= request.getParameter("in1");
String b= request.getParameter("in2");

PortletSession session = request.getPortletSession();
session.setAttribute("a", a , PortletSession.APPLICATION_SCOPE);
session.setAttribute("b", b , PortletSession.APPLICATION_SCOPE);

In the other portlet, you can find it by calling

session.getAttribute("a",PortletSession.APPLICATION_SCOPE);

This, of course, if you can't simply place them in the next page's url.

0
votes

As far as I know IPC does indeed only work between portlets on the same page. Also the portlet specification doesn't provide a generalized mechanism for switching pages so you can only use portal vendor specific ways to achieve that. But using public render parameters and a correctly constructed Liferay URL to another page you should be able to achieve the result you want: http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1207858