CDI Dropping Scope: Spot the Bug?
22 March 2017
It took me a while to get to the bottom of why CDI seemed to be dropping @ViewScoped and @SessionScoped beans. @RequestScope was not behaving properly ether.
It took a lot of digging in the application's codebase and a lot of watching the Debugger before narrowing down the course. Anyway here is the culprit; can you spot the bug?
<h:link outcome="#{navbar.logout()}" >Logout</h:link>
That is from an extract of a composite component that is used on every page of the application. Hence, CDI seemed to be dropping scope.
@Named(value = "navbar") @ApplicationScoped public class Navbar implements Serializable { @Inject private HttpServletRequest request; public String logout() { request.getSession(false).invalidate(); return "/index?faces-redirect=true"; } }
For completeness, the extracts CDI backing bean.
I hope you enjoyed this issue more than I did.
Read : CDI Dropping Scope: Spot the Bug?