1

In SessionListener I want to set some values of @ManagedBean with Session scope that I want to show in JSF.

1 Answer 1

3

You'd need to create the managed bean instance yourself.

Bean bean = new Bean(); bean.setSomething(something); event.getSession().setAttribute("bean", bean); // "bean" is managed bean name. 

JSF will just reuse it if it already exist in the session scope (you see, the JSF "session scope" is under the covers represented by attributes of HttpSession). Note that this way any @PostConstruct won't be invoked and any dependencies which needs to be injected by @ManagedProperty, @EJB, etc, won't be injected at all. You'd need to do it yourself as well.

Designtechnically, much better is to perform the job just in the constructor or @PostConstruct method of the backing bean class itself.

@ManagedBean @SessionScoped public class Bean { @PostConstruct public void init() { // Here. } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.