Portlet Lifecycle, Pluto vs. Liferay

17601, modified 19 Years ago. Junior Member Posts: 61 Join Date: 10/14/05 Recent Posts
Hello all,

I am developing a few new portlets for our intranet portal based on Liferay 4.1.2, Tomcat 5.5.20, and MySQL. I am using Sun's Java Studio Creator 2 Update 1 to build JSF JSR-168 portlets, packaged and deployed as .WAR files, deployed using the hot deploy functions in Liferay. Everything works fine, except for the data-bound table components.

The table component is backed up with a CachedRowSet object. This object is bound to the table during the portlet's init() method. In Pluto, this method is called each time the portlet is loaded, like so:

dataTable1Model.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{PSSessionBean.project_stageRowSet}"));


In Pluto, everything works as it should, and the table displays data. Using the pagination functions of the table works properly, as do column sorts and other functions provided by the table component.

In Liferay, the table displays data on the first view, but any subsequent actions, such as a column sort or page forward causes the data to not be displayed.

After googling around for a bit, I found that others have had this issue as well. It stems from the fact that the portlet lifecycle in Liferay is different from Pluto. More info can be found here:

Sun Forum discussion on portlet lifecycle.

Judging by the posts, as well as my own investigation, it appears that Pluto calls the init() method of a portlet page on every render cycle, where Liferay skips it. I can't seem to find a definitive answer about the expected behavior of a JSR-168 portlet with regards to the init() call. The Spec states that init() is for "costly one-time operations" such as establishing DB connections, etc. In this case, wouldn't Pluto be incorrect in calling it during each refresh cycle?

Regardless, I just need to make it work emoticon . Anybody have any suggestions on where to start?
thumbnail
11365, modified 19 Years ago. Liferay Master Posts: 846 Join Date: 8/5/04 Recent Posts
Neither Pluto or Liferay are incorrect. init() is only meant to be called once for each object "instance" of the portlet, similar to how this works for servlets. So the point is that your init() implementation should not be depend on it being called once per page. The only guarantee is that init() will be called once sometime before render() or processAction().
17601, modified 19 Years ago. Junior Member Posts: 61 Join Date: 10/14/05 Recent Posts
That's about what I expected, given the other similarities between the servlet and portlet models.

I've tried moving the stuff that JSC puts in _init() (which is called by init(), and is the place for auto-generated init code) into prerender(), but the issue is still occurring.

I have a simple .WAR packaged for Liferay that exhibits the problem quite clearly, if anybody else would care to take a look.
thumbnail
11365, modified 19 Years ago. Liferay Master Posts: 846 Join Date: 8/5/04 Recent Posts
If you are using LR 4.2, there are some issues with JSF portlets. 4.2.1 will have this fixed and we are releasing this week.
17601, modified 19 Years ago. Junior Member Posts: 61 Join Date: 10/14/05 Recent Posts
We are actually on 4.1.2. I'll check out 4.2.1 and see if it solves this issue.
thumbnail
27986, modified 19 Years ago. Junior Member Posts: 31 Join Date: 12/15/06 Recent Posts
I have tried this on 4.2.1 and 4.1.3 and the problem exists. This is a major issue with tables that contain changing amounts of data. So far I can't find a fix for it.
thumbnail
27986, modified 19 Years ago. Junior Member Posts: 31 Join Date: 12/15/06 Recent Posts
I have come up with a real ugly solution for this problem. When the table is changed, I setting a session bean variable to tell a phase listener to redirect to another page. The purpose of that other page is to redirect back to this one. This is an ugly way of forceing the Pluto lifecycle. It is working the way I have it, but I hate that I had to do this. Another solution to this problem would be greatly appreciated.

Thanks!
27796, modified 18 Years ago. New Member Posts: 11 Join Date: 12/10/06 Recent Posts
Would calling the refresh method of your data provider in the prerender method of your page bean solve the problem ?
27796, modified 18 Years ago. New Member Posts: 11 Join Date: 12/10/06 Recent Posts
Hi

I've done some research on this. Please look at this Blog post for more information. http://trythisout1.blogspot.com/2007/05/init-method-of-java-studio-creator-page.html
27606, modified 18 Years ago. Junior Member Posts: 32 Join Date: 5/10/07 Recent Posts
I have the same problem!
I use Liferay 4.2.2.

Anyone has found a solution???

Andrea