Foros de discusión

Going nuts trying to get query string params in portlet

Craig Laidlaw, modificado hace 12 años.

Going nuts trying to get query string params in portlet

New Member Mensajes: 9 Fecha de incorporación: 21/11/10 Mensajes recientes
Ok, logistics, running R6.0eeSP1 on tomcat 6.

All I am trying to do is read the query string in a portlet.

I have a page called ctest1 with only one portlet on it.

Here is my doView:

	
public void doView(RenderRequest request, RenderResponse response)
	throws IOException, PortletException {

	HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
	HttpServletRequest hsrequest = PortalUtil.getOriginalServletRequest(httpRequest);
	String queryString = hsrequest.getQueryString();
	
	System.out.println(request.getRemoteUser());
	ThemeDisplay td = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
	
	System.out.println("td is " + td.getUser().getScreenName());
	System.out.println("qstring is " + queryString);

	try {
		System.out.println(PortalUtil.getUser(request).getFullName());
	} catch (PortalException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SystemException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	include(viewJSP, request, response);
}


For the query string http://localhost:8080/group/11205/ctest1?test=1234 I get
11266
td is laidlac
qstring is p_l_id=9088103
Craig Laidlaw

So I read through the forums and see someone suggest that I needed to specify which portlet was to receive the qstring so I tried
http://localhost:8080/group/11205/ctest1?p_l_id=9088103&test=1234 I get the same thing
11266
td is laidlac
qstring is p_l_id=9088103
Craig Laidlaw

Next I went to the Styling area and pulled the portlet id from there
http://localhost:8080/group/11205/ctest1?p_p_id=portlet_dominosredirect_WAR_dominosredirectportlet&test=1234 I still get the same output
11266
td is laidlac
qstring is p_l_id=9088103
Craig Laidlaw


What in the world am I doing wrong that I can't get the portlet to see the test=1234 param in the full query string?
Thanks in advance...
Craig
Antonino Rau, modificado hace 12 años.

RE: Going nuts trying to get query string params in portlet

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
Hi Craig,

use:

http://localhost:8080/group/11205/ctest1?p_p_id=portlet_dominosredirect_WAR_dominosredirectportlet_INSTANCE_5ZhP&_contentclusteringportlet_WAR_contentclusteringportlet_INSTANCE_5ZhP_test=1234

just replace 5ZhP with your portlet instance id.
To find your portlet instance id toggle on the edit control of the page and then open the portlet Configuration->Sharing and under Any Website you'll se something similar to:


.....
<script type="text/javascript">
	Liferay.Widget({ url: 'http://localhost:8080/group/11205/ctest1?
p_p_id=portlet_dominosredirect_WAR_dominosredirectportlet_INSTANCE_[b]=>YOUR_INSTANCE_ID<=[/b]});
</script>


Replace 5ZhP with YOUR_INSTANCE_ID in the example above.
Note that the previous url will invoke the (default) view action, but you can also specify the server side action using portlet_dominosredirect_WAR_dominosredirectportlet_INSTANCE_5ZhP_javax.portlet.action=MY_ACTION (at least for an MVCPortlet)

Regards
Craig Laidlaw, modificado hace 12 años.

RE: Going nuts trying to get query string params in portlet [SOLVED]

New Member Mensajes: 9 Fecha de incorporación: 21/11/10 Mensajes recientes
Antonio, thank you for the quick reply. I went to the Sharing tab and there wasn't an Instance value on the url but that gave me the idea to try a call out using the 'widget' url. I tacked on the extra parameter I was testing for and that full query string popped up in the portlet

http://localhost:8080/widget/group/11205/ctest1/-/dominosredirect_WAR_dominosredirectportlet?test=1234

resulted in query string of p_l_id=9088103&p_p_state=maximized&p_p_lifecycle=0&p_p_id=dominosredirect_WAR_dominosredirectportlet&test=1234&p_p_mode=view

The widget behavior is exactly what I am looking for with the project.

Thank you for your help.
Craig
Antonino Rau, modificado hace 12 años.

RE: Going nuts trying to get query string params in portlet

Junior Member Mensajes: 29 Fecha de incorporación: 25/02/11 Mensajes recientes
Hi Craig,

I'm glad you worked it out.

A clarification: I think your portlet has no instance id because it isn't instanceable.
If you have a portlet with instanceable=true definied in liferay-portlet.xml like:


<liferay-portlet-app>
	<portlet>
		<portlet-name>myPortlet</portlet-name>
		<icon></icon>
		[b]<instanceable>true</instanceable>[/b]
                  .....
	</portlet>
</liferay-portlet-app>


then you will need also the instance id. In fact you could have more then one portlet instance per page and then the portal needs an id to route the parameter to the right portlet.

Regards,
Antonino