Fórum

PROBLEM: public render parameters Liferay 6

Gabriel Palacios, modificado 12 Anos atrás.

PROBLEM: public render parameters Liferay 6

Junior Member Postagens: 31 Data de Entrada: 18/11/11 Postagens Recentes
Hi everyone.

I'm having issues passing a render parameter to an asset publisher portlet, and im starting to think i don't know how it works (ive been playing with liferay for 3 days).

I have two portlets in ah page:
- first, a custom portlet that renders a <select> with category name in its display (ie: "Albacete", "Burgos", "Cuenca", spanish provinces) and categoryId in its value.
- last, a standard asset publisher that shows all the content with category "OFFICES_NETWORK"
I want to pass the province (categoryId) to the asset publisher.

My category tree looks like this:
-"OFFICES_NETWORK"
      -"Albacete"
      -"Burgos"
      -"Cuenca"


When selecting a province and pressing a submit input, I send the categoryId of the province to my custom portlet's processAction (form name="province") method and there do the following:
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException,
	PortletException
{
	String provinceId = actionRequest.getParameter("province");

	if (!StringUtils.isEmpty(provinceId))
		actionResponse.setRenderParameter("provinceId", provinceId);
	else
		actionResponse.removePublicRenderParameter("provinceId");

	super.processAction(actionRequest, actionResponse);
}

I correctly receive the categoryId/provinceId in the method.

I also defined in my portlets' portlet.xml
<portlet-app>
	<portlet>
		[...]
		<supported-public-render-parameter>provinceId</supported-public-render-parameter>
	</portlet>
</portlet-app>
<public-render-parameter>
	<identifier>provinceId</identifier>
	<qname xmlns:company="http://www.company.com/public-render-parameters">company:provinceId</qname>
</public-render-parameter>


My portal-ext.properties contains the following lines:
portlet.public.render.parameter.distribution=layout-set
layout.default.p_l_reset=false


I also tried
portlet.public.render.parameter.distribution=layout

and
portlet.public.render.parameter.distribution=ALL_PORTLETS


In asset publisher's configuration, at communication tab, the "categoryId" shared parameter reads its value from "provinceId" (which is listed in the combo).

I tried many and many combinations but the asset publisher portlet keeps showing all the all the content with category "OFFICES_NETWORK" and doesnt filter by province.

What am I doing wrong?!?
Pleeeeeeeeeease, I've been stuck for hours!!!!!
thumbnail
Tanweer Ahmed ., modificado 1 Ano atrás.

RE: PROBLEM: public render parameters Liferay 6

Expert Postagens: 322 Data de Entrada: 11/03/10 Postagens Recentes
Hi Gabriel,

Can you try sharing your values using PortletSession or HttpSession .If you are using Portlet Session, set the session scope as Application.
Also add the private-session-attributes property as false in liferay-portlet.xml.Let me know if this works.

Hope this helps,
Regards,
Tanweer
mPowerian-BoschLer
Gabriel Palacios, modificado 12 Anos atrás.

RE: PROBLEM: public render parameters Liferay 6

Junior Member Postagens: 31 Data de Entrada: 18/11/11 Postagens Recentes
I'll try that inmediatly emoticon
So, am I doing things right? Is it a liferay bug or something?
thumbnail
Samir Gami, modificado 12 Anos atrás.

RE: PROBLEM: public render parameters Liferay 6

Regular Member Postagens: 162 Data de Entrada: 04/02/11 Postagens Recentes
Gabriel Palacios:
I'll try that inmediatly emoticon
So, am I doing things right? Is it a liferay bug or something?


Public Render Parameters are not working in SP2,
http://www.liferay.com/community/forums/-/message_boards/message/11588470
Gabriel Palacios, modificado 12 Anos atrás.

RE: PROBLEM: public render parameters Liferay 6

Junior Member Postagens: 31 Data de Entrada: 18/11/11 Postagens Recentes
i already tried adding this
actionRequest.getPortletSession().setAttribute("provinceId", provinceId, PortletSession.APPLICATION_SCOPE);

to my processAction method

Still not working. I wonder how the asset publisher was going to receive that value ...
Any other thoughts?? please emoticon
Gabriel Palacios, modificado 12 Anos atrás.

RE: PROBLEM: public render parameters Liferay 6

Junior Member Postagens: 31 Data de Entrada: 18/11/11 Postagens Recentes
Theres one thing I noticed:

even if asset publisher has got two public parameters ('categoryId' and 'tag'), these parameters don't seem to be neither in actionRequest.getPublicParameterMap() nor in actionResponse.getRenderParameterMap()

Does this makes sense to someone?? Could it be something related to portlet.public.render.parameter.distribution property?
Gabriel Palacios, modificado 12 Anos atrás.

RE: PROBLEM: public render parameters Liferay 6

Junior Member Postagens: 31 Data de Entrada: 18/11/11 Postagens Recentes
Ok, i finally managed to do it. I'll explain how.

As i wasnt able to get the asset publisher to read my value provinceId, I added a category navigation portlet.
With this portlet I was able to change the category that the asset publisher was showing. So I went and gave a look to the source code of the portlet's view.

In short, each link of the category navigation portlet had it's location built this way:
&lt;% 
   PortletURL portletURL = renderResponse.createRenderURL(); 
   or (AssetCategory category : categories) {
   { 
      portletURL.setParameter("categoryId", String.valueOf(category.getCategoryId())); %&gt;
      <a href="<%= portletURL.toString() %>">&lt;%= category.getName() %&gt;</a>
&lt;%
   } %&gt;

I inspected what was the rendered URL and I found this attribute: p_r_p_564233524_categoryId
Then, I copy-pasted this same code in my custom portlet, setting provinceId instead of categoryId and the attribute in the URL was: p_r_p_0_provinceId

Every time I tried to add provinceId to the public parameters in my processAction method, I got the defined qname in portlet.xml in front of it. Ie: http://www.liferay.com/public-render-parameters_provinceId
I tried to set this attribute programatically, but I couldn't find where to get the p_r_p_0 bit, or how to build it.

So, having a <select> (and not links like in the asset category navigation), I had to throw some js lines to change action's form. The result was this:

<script>
	var portletUrls = {};

	function buildPortletUrl()
	{
		var form = document.getElementById('provinceForm');
		var provinceId = document.getElementById('provinceSelect').value;

		if (provinceId) form.action = portletUrls[provinceId];	
	}
</script>

<form id="provinceForm" action="<%= actionURL %>" method="POST">

	<select id="provinceSelect" name="province">
		 
	&lt;%	String[] provinceIds = (String[])request.getAttribute("provinceIds");
		String[] provinceNames = (String[])request.getAttribute("provinceNames");
		 
		String selectedProvince = request.getParameter("province");	 
		Integer provinces = (Integer)request.getAttribute("provinces");
		for (int index = 0; index &lt; provinces; index++)
		{ 
			portletURL.setParameter("provinceId", String.valueOf(provinceIds[index])); %&gt;
	
			<option value="<%= provinceIds[index] %>" <% if (selectedprovince !="null" && selectedprovince.equals(provinceids[index])) { %> selected="selected"&lt;% } %&gt;&gt;
				&lt;%= provinceNames[index] %&gt;
			</option>
			&lt;%  %&gt;
			<script> portletUrls['<%= provinceIds[index] %>'] = '<%= portletURL.toString() %>' </script>
	&lt;%	} %&gt;
	</select>
	
	<input class="button" type="submit" value="Search" onclick="javascript:buildPortletUrl()">
</form>


So my question is, ¿how to build that p_r_p_0_provinceId programatically in my processAction method?
Nasir Hussain, modificado 9 Anos atrás.

RE: PROBLEM: public render parameters Liferay 6

New Member Postagens: 18 Data de Entrada: 26/04/10 Postagens Recentes
portlet.public.render.parameter.distribution=ALL_PORTLETS


There is no such thing as all portlets, if you give portlet.public.render.parameter.distribution=MY_MOM this will also work correctly.
check the code yourself, only condition check is for layout, otherwise it is treated as layout-set

public class PublicRenderParametersPool {

public static Map<String, String[]> get(
HttpServletRequest request, long plid) {

if (PropsValues.PORTLET_PUBLIC_RENDER_PARAMETER_DISTRIBUTION_LAYOUT) {
return RenderParametersPool.get(
request, plid, _PUBLIC_RENDER_PARAMETERS);
}

HttpSession session = request.getSession();

Map<Long, Map<String, String[]>> publicRenderParametersPool =
(Map<Long, Map<String, String[]>>)session.getAttribute(
WebKeys.PUBLIC_RENDER_PARAMETERS_POOL);

if (publicRenderParametersPool == null) {
publicRenderParametersPool =
new ConcurrentHashMap<Long, Map<String, String[]>>();

session.setAttribute(
WebKeys.PUBLIC_RENDER_PARAMETERS_POOL,
publicRenderParametersPool);
}

try {
Layout layout = LayoutLocalServiceUtil.getLayout(plid);

LayoutSet layoutSet = layout.getLayoutSet();

Map<String, String[]> publicRenderParameters =
publicRenderParametersPool.get(layoutSet.getLayoutSetId());

if (publicRenderParameters == null) {
publicRenderParameters = new HashMap<String, String[]>();

publicRenderParametersPool.put(
layoutSet.getLayoutSetId(), publicRenderParameters);
}

return publicRenderParameters;
}
catch (Exception e) {
if (_log.isWarnEnabled()) {
_log.warn(e, e);
}

return new HashMap<String, String[]>();
}
}

private static final String _PUBLIC_RENDER_PARAMETERS =
"PUBLIC_RENDER_PARAMETERS";

private static Log _log = LogFactoryUtil.getLog(
PublicRenderParametersPool.class);

}