Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Juan Jose Vazquez
ViewScoped controllers behaviour
September 18, 2012 4:04 AM
Answer

Juan Jose Vazquez

Rank: New Member

Posts: 6

Join Date: August 15, 2012

Recent Posts

Hi all,

Recently, I´ve stumbled across an unexpected behavior regarding view scoped controllers with 2 or more portlet instances in the same portal page. The truth is that I don't really know whether this is a problem with my project configuration or reveals a misconception about how the Liferay Faces Bridge works.

The situation is reproduced as follows:

* Drop two instances of the same or different portlet in the same portal page.
* Each portlet has several views each with its controller annotated as @ViewScoped.
* Each controller has an init() method annotated as @PostConstruct.

The behavior I'm seeing is that when a portlet instance changes of view, the other remains in the same view, as I expected, but its controller is reinitialized. My assumption about how the bridge works was that this latter controller wouldn't be reinitialized as its view remains unchanged.

As I said before, at this point I don't know whether this is the normal behaviour I have to expect or not.

Any help is appreciated.

My environment is:

Liferay 6.1.1 CE GA2
Mojarra 2.1.10
Liferay Faces Bridge 3.1.0 GA1

BR,

Juanjo
Neil Griffin
RE: ViewScoped controllers behaviour
September 19, 2012 9:27 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2336

Join Date: July 26, 2005

Recent Posts

Hi Juanjo,

When you click to invoke the navigation, are you using Ajax or are you doing a full HTTP postback (no Ajax)?

Neil
Juan Jose Vazquez
RE: ViewScoped controllers behaviour
September 19, 2012 9:30 AM
Answer

Juan Jose Vazquez

Rank: New Member

Posts: 6

Join Date: August 15, 2012

Recent Posts

Hi Neil,

It's a full HTTP postback.

BR,

Juanjo.
Neil Griffin
RE: ViewScoped controllers behaviour
September 19, 2012 9:41 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2336

Join Date: July 26, 2005

Recent Posts

The JSR 329 standard defines portlet re-render requirements for this with @RequestScoped managed-beans, but since JSR 329 is concerned with JSF 1.2 (and not JSF 2.x), there aren't any requirements for @ViewScoped managed-beans. So I think this is a Portlet 2.0 + JSF 2.x use-case that we haven't run into yet.

Would you be able to use f:ajax in the portlet that is doing the navigation? I think that might work as a workaround.
Juan Jose Vazquez
RE: ViewScoped controllers behaviour
September 19, 2012 10:28 AM
Answer

Juan Jose Vazquez

Rank: New Member

Posts: 6

Join Date: August 15, 2012

Recent Posts

I will study the possibility of using f:ajax. But, in order to understand you correctly, do yo mean that I wouldn't have this behaviour if I used @RequestScoped beans?. I've tried it using @RequestScoped beans with the same result.

Thanks in advance,

Juanjo.
Neil Griffin
RE: ViewScoped controllers behaviour
September 19, 2012 10:36 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2336

Join Date: July 26, 2005

Recent Posts

Thanks for asking for clarification -- For performance reasons, the @RequestScoped feature is disabled by default in Liferay Faces Bridge. Please read section 7.2 of the documentation titled "Bridge Request Scope" for more information. Example 7.1 shows how to enable the feature.
Juan Jose Vazquez
RE: ViewScoped controllers behaviour
September 20, 2012 6:48 AM
Answer

Juan Jose Vazquez

Rank: New Member

Posts: 6

Join Date: August 15, 2012

Recent Posts

After doing some tests, I think it is best to apply an Ajax based navigation. In this way, navigation behaviour seems more expected.

Thanks for your help and support!.

BR,

Juanjo.
Neil Griffin
RE: ViewScoped controllers behaviour
September 20, 2012 7:07 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2336

Join Date: July 26, 2005

Recent Posts

My pleasure Juanjo. Navigation with f:ajax is a very nice feature of JSF2 and fits pretty well with the portlet use-case I think.