1

In this post Dynamic ui:include I asked how I could store an object in some state that could permit me to load a new windows, or tab, of the same browser and it was not stored also in the new windows. Adrian Mitev told me to use @WindowScoped, an option of MyFaces extension called CODI and i tried to implement it.

Now I should say that I'm blind and when I tried to open Apache Wiki my browser crashes on many pages so I can't read the guides.

However I add the source code on my project and the compiler didn't give any errors. The problem is that now thepage when I try to retrive the bean that I stored by @WindowScoped doesn't work properly!

I use this code in my bean:

@ManagedBean (name="logicBean" )
@WindowScoped

In include.xhtml I retrieve the parameter with this code:

<ui:include src="#{logicBean.pageIncluded}"/> 

And in my other beans I retrieve the LogicBean with this code (and I'm sure that the problem is on this code)

LogicBean l = (LogicBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("logicBean");

How can I retrive the "correct" LogicBean object?

Community
  • 1
  • 1
Filippo1980
  • 2,745
  • 5
  • 30
  • 44

1 Answers1

2

You're trying to get the LoginBean from the session map. This works only for session scoped beans with the standard JSF @SessionScoped annotation.

The canonical way to access other beans is using @ManagedProperty on the retrieving bean.

E.g.

@ManagedBean
@RequestScoped
public class OtherBean {

    @ManagedProperty("#{logicBean}")
    private LogicBean logicBean;

    // Getter+Setter.
}

If you really need to access it inside the method block by evaluating the EL programmatically, you should be using Application#evaluateExpressionGet() instead:

FacesContext context = FacesContext.getCurrentInstance();
LogicBean logicBean = context.getApplication().evaluateExpressionGet(context, "#{logicBean}", LogicBean.class);
// ...
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • @ BalusC : Thank you very much! I knew that the code retrivied the object on the session but I didn't know how I could change it! Thanks again! – Filippo1980 Jan 18 '12 at 14:57