0

I have been studying new java 1.8 + CDI + WildFly And JSF 2.2.

I´ve read a lot about the scopes and still can´t figure out which scope should i use or what is the best practice to get a single controller to work with diferent views.

Can´t use the @ViewScoped because it works just for one view. @SessionScoped doesn´t look like the right path, and @ConversationScope looks like too much for what I´m looking for.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
JoseGarcia
  • 11
  • 1

2 Answers2

0

Then use the DeltaSpike @ViewAccessScoped

From their docs (emphasis mine)

In case of conversations you have to un-scope beans manually (or they will be terminated automatically after a timeout). However, sometimes you need beans with a lifetime which is as long as needed and as short as possible - which are terminated automatically (as soon as possible). In such an use-case you can use this scope. The simple rule is, as long as the bean is referenced by a page - the bean will be available for the next page (if it is used again the bean will be forwarded again). It is important that it is based on the view-id of a page (it is not based on the request) so, for example, Ajax requests do not trigger a cleanup if the request does not access all view-access scoped beans of the page. That’s also the reason for the name @ViewAccessScoped.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
0

If you have a defined entry point and exit point in your application, you can use JSF 2.2 @FlowScope

What is a Faces flow?

A collection of JSF views (and related artifacts) with explicitly
defined entry and exit points that have been assigned some application specific meaning by the developer. Usually the objects in a faces flow are designed to allow the user to accomplish a task that requires input over a number of different views. The canonical example of a flow is an "order checkout" process where the user enters in address, payment, shipping information, etc., and then submits the entire result at the end, placing an order.

source: https://javaserverfaces-spec-public.java.net/nonav/proposals/JAVASERVERFACES_SPEC_PUBLIC-730/proposal.txt

Zim
  • 1,457
  • 1
  • 10
  • 21