I’m writing a Vaadin portlet(which implements PortletApplicationContext2.PortletListener) for Liferay. I would like my portlet to read and display a parameter from the page URL.
For instance, if I navigate to:
http://localhost:8080/web/guest/test-page?foo=bar
…then I would like to set a Label in my portlet with the value of foo, so it would display “bar” in this case.
You cannot read them in a portlet - the Portlet 2.0 (JSR-286) spec does not support this. With JSR-286, portlet URLs have to be generated on the server side with a special API, and parameters set for them when the URL is created the server. The URL formats vary hugely between portals, and the parameters you set for a portlet URL might not even be encoded in the URL at all but kept on the server, or encoded in a complex way.
There are some portal specific workarounds or alternative approaches in some cases - you might e.g. want to use a
FriendlyURLMapper on Liferay.
Thanks for your response. I was actually able to find a different way to get this to work in Liferay, using their
com.liferay.portal.util package:
public void handleRenderRequest(RenderRequest request,
RenderResponse response, Window window) {
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
final String foo= PortalUtil.getOriginalServletRequest(httpRequest).getParameter("foo");
}
Of course, like you said, this only works for http requests, not JSR-286 requests. But if you’re passing parameters between pages instead of directly between portlets, it works well.