Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gabriel Palacios
PROBLEM: public render parameters Liferay 6
November 18, 2011 5:57 AM
Answer

Gabriel Palacios

Rank: Junior Member

Posts: 31

Join Date: November 18, 2011

Recent Posts

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:
1-"OFFICES_NETWORK"
2      -"Albacete"
3      -"Burgos"
4      -"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:
 1public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException,
 2    PortletException
 3{
 4    String provinceId = actionRequest.getParameter("province");
 5
 6    if (!StringUtils.isEmpty(provinceId))
 7        actionResponse.setRenderParameter("provinceId", provinceId);
 8    else
 9        actionResponse.removePublicRenderParameter("provinceId");
10
11    super.processAction(actionRequest, actionResponse);
12}

I correctly receive the categoryId/provinceId in the method.

I also defined in my portlets' portlet.xml
 1<portlet-app>
 2    <portlet>
 3        [...]
 4        <supported-public-render-parameter>provinceId</supported-public-render-parameter>
 5    </portlet>
 6</portlet-app>
 7<public-render-parameter>
 8    <identifier>provinceId</identifier>
 9    <qname xmlns:company="http://www.company.com/public-render-parameters">company:provinceId</qname>
10</public-render-parameter>


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


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

and
1portlet.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!!!!!
Tanweer .
RE: PROBLEM: public render parameters Liferay 6
November 18, 2011 10:08 PM
Answer

Tanweer .

Rank: Expert

Posts: 272

Join Date: March 11, 2010

Recent Posts

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
RE: PROBLEM: public render parameters Liferay 6
November 20, 2011 10:55 PM
Answer

Gabriel Palacios

Rank: Junior Member

Posts: 31

Join Date: November 18, 2011

Recent Posts

I'll try that inmediatly emoticon
So, am I doing things right? Is it a liferay bug or something?
Gabriel Palacios
RE: PROBLEM: public render parameters Liferay 6
November 20, 2011 11:15 PM
Answer

Gabriel Palacios

Rank: Junior Member

Posts: 31

Join Date: November 18, 2011

Recent Posts

i already tried adding this
1actionRequest.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
RE: PROBLEM: public render parameters Liferay 6
November 20, 2011 11:39 PM
Answer

Gabriel Palacios

Rank: Junior Member

Posts: 31

Join Date: November 18, 2011

Recent Posts

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
RE: PROBLEM: public render parameters Liferay 6
November 23, 2011 3:28 AM
Answer

Gabriel Palacios

Rank: Junior Member

Posts: 31

Join Date: November 18, 2011

Recent Posts

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:
1<%
2   PortletURL portletURL = renderResponse.createRenderURL();
3   or (AssetCategory category : categories) {
4   {
5      portletURL.setParameter("categoryId", String.valueOf(category.getCategoryId())); %>
6      <a href="<%= portletURL.toString() %>"><%= category.getName() %></a>
7<%
8   } %>

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:

 1<script>
 2    var portletUrls = {};
 3
 4    function buildPortletUrl()
 5    {
 6        var form = document.getElementById('provinceForm');
 7        var provinceId = document.getElementById('provinceSelect').value;
 8
 9        if (provinceId) form.action = portletUrls[provinceId];   
10    }
11</script>
12
13<form id="provinceForm" action="<%= actionURL %>" method="POST">
14
15    <select id="provinceSelect" name="province">
16         
17    <%    String[] provinceIds = (String[])request.getAttribute("provinceIds");
18        String[] provinceNames = (String[])request.getAttribute("provinceNames");
19         
20        String selectedProvince = request.getParameter("province");    
21        Integer provinces = (Integer)request.getAttribute("provinces");
22        for (int index = 0; index < provinces; index++)
23        {
24            portletURL.setParameter("provinceId", String.valueOf(provinceIds[index])); %>
25   
26            <option value="<%= provinceIds[index] %>"
27            <% if (selectedProvince != null && selectedProvince.equals(provinceIds[index])) { %> selected="selected"<% } %>>
28                <%= provinceNames[index] %>
29            </option>
30            <%  %>
31            <script> portletUrls['<%= provinceIds[index] %>'] = '<%= portletURL.toString() %>' </script>
32    <%    } %>
33    </select>
34   
35    <input class="button" type="submit" value="Search" onclick="javascript:buildPortletUrl()"/>
36</form>


So my question is, ¿how to build that p_r_p_0_provinceId programatically in my processAction method?
Samir Gami
RE: PROBLEM: public render parameters Liferay 6
November 25, 2011 12:11 AM
Answer

Samir Gami

Rank: Regular Member

Posts: 159

Join Date: February 3, 2011

Recent Posts

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
Nasir Hussain
RE: PROBLEM: public render parameters Liferay 6
June 15, 2014 12:17 AM
Answer

Nasir Hussain

Rank: New Member

Posts: 5

Join Date: April 26, 2010

Recent Posts

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);

}