-1

Within my (JSF, Servlet 3.0) sessionscope there are instances of classes. How can I get the instance of a class by using the names provided in sessionscope?

For example, in my session there is a instance of MyBean:

classes-ManagedBean-class com.MyBean=Bean: Managed Bean [class com.MyBean] with qualifiers [@Any @Default @Named]; Instance: com.MyBean@40a6d41f

In java code, I want to retrieve the actual instance of MyBean:

HttpSession session = us.getHttpSession();
MyBean mybean = (MyBean) session.getAttribute("???");

Which value should I provide for '???'

4

2 回答 2

0

this what you after :

FacesContext context = FacesContext.getCurrentInstance();
MyBean mybean =  (MyBean) context.getExternalContext().getSessionMap().get("myBean");

Note that myBean is the name of the managed bean

for example @ManagedBean(name = "myBean ") , if no (name = "myBean ") is specified the default will be the same as class name with first letter in lower case

于 2012-10-15T12:28:29.017 回答
0

The above is retrieved from SessionMap. I made a workaround by putting a key explicitly in sessionmap again. Now it works

于 2012-10-15T13:38:07.160 回答