Wednesday, May 15, 2013

JSF2.2 ViewScope Using CDI

JSF 2.0 introduced annotation @ViewScoped; A bean annotated with this scope maintained its state as long as the user stays on the same view(reloads or navigation - no intervening views).

One problem with the @ViewScoped is that it doesn't work with CDI (@Named); so one had to annotate bean as @ManagedBean to be ViewScoped.

JSF2.2 has introduced a NEW annotation @ViewScoped in javax.faces.view.ViewScoped (NOT reusing the existing javax.faces.bean.ViewScoped) which is CDI compatible.

Here is a working sample using Glassfish B4 v72.

Click here to download source code




Prasanna Bhale


2 comments: