掲示板

ViewScoped controllers behaviour

11年前 に Juan Jose Vazquez によって更新されました。

ViewScoped controllers behaviour

New Member 投稿: 6 参加年月日: 12/08/15 最新の投稿
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
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: ViewScoped controllers behaviour

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Juanjo,

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

Neil
11年前 に Juan Jose Vazquez によって更新されました。

RE: ViewScoped controllers behaviour

New Member 投稿: 6 参加年月日: 12/08/15 最新の投稿
Hi Neil,

It's a full HTTP postback.

BR,

Juanjo.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: ViewScoped controllers behaviour

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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.
11年前 に Juan Jose Vazquez によって更新されました。

RE: ViewScoped controllers behaviour

New Member 投稿: 6 参加年月日: 12/08/15 最新の投稿
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.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: ViewScoped controllers behaviour

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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.
11年前 に Juan Jose Vazquez によって更新されました。

RE: ViewScoped controllers behaviour

New Member 投稿: 6 参加年月日: 12/08/15 最新の投稿
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.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: ViewScoped controllers behaviour

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
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.