JSF Tip #30 - Migrate your ManagedBean to Named annotations

Since JSF 2.2 we consider the old style @ManagedBean annotation deprecated, but what now you would say? Well it is pretty straightforward.

  1. Change @ManagedBean(name="xxx") to @Named("xxx")
  2. Change the package imports for your @XXXScoped annotations to the CDI equivalents

    From                                To

    javax.faces.bean.ApplicationScoped  javax.enterprise.context.ApplicationScoped
    javax.faces.bean.RequestScoped      javax.enterprise.context.RequestScoped
    javax.faces.bean.SessionScoped      javax.enterprise.context.SessionScoped
    javax.faces.bean.ViewScoped         javax.faces.view.ViewScoped

Note JSF 2.2 supports more scopes, but they are new so they are not mentioned in the table above. Future blog entries will touch on those new scopes.

Posted October 30, 2013