5/27/2011

How to read GET parameters with JSF in Liferay

I think you all know the problem: You want to pass some parameters from portlet 1 to portlet 2 but unformtunately you can´t use Inter-Portlet Communication because the other portlet is on another portlet page. Simple using http://localhost:8080/web/guest/home?parameter=helloWorld doesn`t really help. Well, here is the solution to your problem:


First, you need to find out your portlets ID. This you need to extend your link. A portlet ID in liferay looks pretty much like this:


p_p_id=3_WAR_yourportletname_INSTANCE_A8sO


You can find out your portlets id by maximizing it and taking a look at the address field of your browser. There you will find the ID. You now need to add the ID as the first parameter to your URL:


http://localhost:8080/web/guest/home?p_p_id=3_WAR_yourportletname_INSTANCE_A8sO&parameter=helloWorld


This makes sure, that your JSF - Portlet has access to the parameters. Now you need to retrieve them from the request by using this code snippet:

RenderRequest renderRequest = (RenderRequest) (FacesContext .getCurrentInstance()
.getExternalContext().getRequestMap() .get("javax.portlet.request")); 
String parameter = renderRequest.getParameter("parameter");



If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.