Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Micael Ericsson
Public Render Param between pages
January 14, 2013 6:38 AM
Answer

Micael Ericsson

Rank: Junior Member

Posts: 88

Join Date: December 11, 2012

Recent Posts

I have started a portal project - Java / JSF 2 / Portlet on Tomcat/Liferay.
The portal consists of several pages each with one or more portlets.
The user starts the portal with a selection of type. This type is used through the portal in all portlets for this user.

I have made a test with public render param (Parameter name type-id). (JSR 286)
Page 1/Portlet 1 sets the type-id. If Portlet 2 is on same page as Portlet 1 it can read type-id (from public render param).
But if Portlet 2 is on page 2 parameter type-id is null.

In portal.xml (for both projects/portlets) I have defined:
<supported-public-render-parameter>type-id</supported-public-render-parameter>
and
<public-render-parameter>
<identifier>type-id</identifier>
<qname xmlns:x="http://www.sun.com/params">x:type-id</qname>
</public-render-parameter>

In Portlet 1 I set parameter with:
FacesContext facesContext = FacesContext.getCurrentInstance();
Object responseObject = facesContext.getExternalContext().getResponse();
ActionResponse actionResponse = (ActionResponse) responseObject;
actionResponse.setRenderParameter("type-id", "1");

In portlet 2 I read parameter with:
FacesContext context = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
String value = request.getParameter("type-id");

According to what I have read about JSR 286 it's by default a global parameter.

Suggestions on where the problem is?
Stian Sigvartsen
RE: Public Render Param between pages
January 14, 2013 7:01 AM
Answer

Stian Sigvartsen

Rank: Junior Member

Posts: 97

Join Date: August 27, 2010

Recent Posts

Hi Micael

Depending on the complexity of portlet1, you might be able to achieve what you want by selecting page2 from the "Link Portlet URLs to Page" dropdown box within portlet1's "Look and Feel" configuration. This would certainly make the public render parameter available to portlet2 on page2, but means ALL URLs generated by portlet1 will go to page2. It's a shame that Liferay offers no means by which to redirect only certain URLs, though I appreciate the complexity in achieving a robust implementation of this.

P.S. It would be great to hear from anyone who is concerned about that issue and possibly have an elegant solution to it.

-Stian
Micael Ericsson
RE: Public Render Param between pages
January 14, 2013 7:09 AM
Answer

Micael Ericsson

Rank: Junior Member

Posts: 88

Join Date: December 11, 2012

Recent Posts

Stian Sigvartsen:
Hi Micael

Depending on the complexity of portlet1, you might be able to achieve what you want by selecting page2 from the "Link Portlet URLs to Page" dropdown box within portlet1's "Look and Feel" configuration. This would certainly make the public render parameter available to portlet2 on page2, but means ALL URLs generated by portlet1 will go to page2. It's a shame that Liferay offers no means by which to redirect only certain URLs, though I appreciate the complexity in achieving a robust implementation of this.

P.S. It would be great to hear from anyone who is concerned about that issue and possibly have an elegant solution to it.

-Stian


The navigation and use of type-id is a bit more complex than your suggestion.

On first page users selects a type. Then the actual start page for selected type is loaded. This start page has a menu portlet which has a number of links depending on selected type. Linked pages with theirs portlets continue to use the type-id.

This is more a global param per user than links between pages.
Neil Griffin
RE: Public Render Param between pages
January 14, 2013 8:58 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2040

Join Date: July 26, 2005

Recent Posts

This is more a global param per user than links between pages.


Sounds like this might be a good use-case for a PortletSession attribute.
Micael Ericsson
RE: Public Render Param between pages
January 15, 2013 12:18 AM
Answer

Micael Ericsson

Rank: Junior Member

Posts: 88

Join Date: December 11, 2012

Recent Posts

So I switched to PortletSession attributes. This is what I have done (+ removing old public render param settings).

Added in both portlets liferay-portlet.xml
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>

In portlet 1 I set attribute with:
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest();
PortletSession session = request.getPortletSession(false);
session.setAttribute("type-id", "1", PortletSession.APPLICATION_SCOPE);

In portlet 2 I read with:
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest();
PortletSession session = request.getPortletSession(false);
String value = (String) session.getAttribute("type-id", PortletSession.APPLICATION_SCOPE);

When I run this setting works fine but when reading attribute I get an error:
08:07:16,231 ERROR [BridgePhaseBaseImpl:247] Found render parameter name=[Logincom.liferay.faces.bridge.bridgeRequestScopeId] value=[Login:::1781F105A9F6F71040CB5E1732924925:::1358237232751] BUT bridgeRequestScope is NOT in the cache

I have also tried with only this row in liferay-portlet.xml with same result.
<private-session-attributes>false</private-session-attributes>
Neil Griffin
RE: Public Render Param between pages
January 15, 2013 1:37 PM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2040

Join Date: July 26, 2005

Recent Posts

Are you sure that you need to specify the following as false?

1<private-request-attributes>false</private-request-attributes>

This can be problematic. According to the Liferay FAQ Wiki page:

"This method can possibly result in a ClassCastException (especially for multiple portlets in multiple WARs) and is therefore not recommended"

Also, when you get a chance please explain why you need the following to be false:

1<private-session-attributes>false</private-session-attributes>
Micael Ericsson
RE: Public Render Param between pages
January 21, 2013 12:56 AM
Answer

Micael Ericsson

Rank: Junior Member

Posts: 88

Join Date: December 11, 2012

Recent Posts

Neil Griffin:
Are you sure that you need to specify the following as false?

1<private-request-attributes>false</private-request-attributes>

This can be problematic. According to the Liferay FAQ Wiki page:

"This method can possibly result in a ClassCastException (especially for multiple portlets in multiple WARs) and is therefore not recommended"

Also, when you get a chance please explain why you need the following to be false:

1<private-session-attributes>false</private-session-attributes>


The private-session-attributes was something I found in a sample. Removing them solved my problem. Thanks for the solution.
Micael Ericsson
RE: Public Render Param between pages
January 28, 2013 3:41 AM
Answer

Micael Ericsson

Rank: Junior Member

Posts: 88

Join Date: December 11, 2012

Recent Posts

The problem was not solved. I forgot I made som hard codeing for a quick demo. The hard coding was still there when I tested without setting in liferay-portlet.xml. emoticon

With hard coding removed I can't get "passing data" to work.

I have two separate portlets (two war files). These two portlets are on different Liferay pages.
I set data with:
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest();
PortletSession session = request.getPortletSession(false);
session.setAttribute("typeid", "1", PortletSession.APPLICATION_SCOPE);

I read data with:
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest();
PortletSession session = request.getPortletSession(false);
String value = (String) session.getAttribute("typeid", PortletSession.APPLICATION_SCOPE);

But when reading the data is always null.

The liferay-portlet.xml and the portlet.xml contains not other data than standard for portlet and roles.
Micael Ericsson
RE: Public Render Param between pages
September 10, 2013 1:40 AM
Answer

Micael Ericsson

Rank: Junior Member

Posts: 88

Join Date: December 11, 2012

Recent Posts

It's time to bump this thread alive again.

- Public Render Param works between two portlets on same Liferay page.
- PortletSession params work between two portlets on different pages, but requires that these portlets are in the same war-file.

In my case all portlets are in separate war-files and appears in different Liferay pages.

So far I have solved this by a happy hacking, but now is it time to create a proper solution. One would be to use cookies but that's no a solution we would like to use in this project. Another solution is to use query param but this doesn't work in our navigation model.

Suggestions to solution?
Demands:
- Function to send param data between two portlets on different pages
- JSF 2
- Liferay 6.1
- Portlets, each in different war-file and on different page
- Not by cookies
- Not by query param
Vernon Singleton
RE: Public Render Param between pages
September 10, 2013 7:24 AM
Answer

Vernon Singleton

LIFERAY STAFF

Rank: Regular Member

Posts: 168

Join Date: January 14, 2013

Recent Posts

Micael Ericsson:
- Function to send param data between two portlets on different pages
- JSF 2
- Liferay 6.1
- Portlets, each in different war-file and on different page
- Not by cookies
- Not by query param


Sounds like you need to take a look at the Inter Portlet Communication demos for JSF2:
https://www.liferay.com/community/liferay-projects/liferay-faces/demos#Inter-Portlet%20Communication%20(IPC)

Please consider trying out the Customers and Bookings portlets and taking a look at the source code for each one to see if IPC Events will work for your needs.

For Liferay 6.1 you can use the recently released 3.1.3-ga4 versions of those demo portlets.

Hope that helps,
Vernon