Bertie
Bertie

Reputation: 17697

JSF CDI : Conversation scope bean[s] best practice

I'm currently learning about JSF 2.0 and im so glad for the existence of this conversation scope feature, which is very helpful in opening a new tab or a new window on the same page and having separate resources, not overriding one another.

But im curious on how to implement this in a good way, about when to start the conversation and when to close it.

In my case, i have each CDI bean for each JSF page. And let's say that i have a menu, and when it's clicked, this will lead to page A, and from A, could lead to B, B could lead to C, C could lead to D, all these 4 pages are connected in one chain.

Accessing A's bean properties from B or C or D beans is possible, accessing B's properties is also possible from C or D beans and so forth.

Now im quite confused about :

Please share your thoughts on this.

Upvotes: 11

Views: 13969

Answers (1)

Brian Leathem
Brian Leathem

Reputation: 4639

JSF 2 provides Request, View, Session, and Application scopes. CDI introduces the Conversation scope, but more importantly, it introduces a standard by which new scopes can be added to the platform.

The Scope you are describing is probably better suited by a custom scope like a window scope. Two projects implementing this scope are:

  1. Apache MyFaces CODI
  2. IceFaces has a JSF (non-CDI) Window scope implementation.

Nevertheless, I would encourage you to rethink your bean structure. I've become quite fond of the View scope myself, coupled with the JSF 2 view parameters to propagate information from one page to another (and from one View scope instance to another).

MyFaces "View Access" scope seems like another neat approach, where a bean stays in scope so long as the pages you navigate through maintain a reference to that scope.

Upvotes: 11

Related Questions