Question

i search a way how i can access a class in the sessionscope.

I have this class:

@ManagedBean
@SessionScoped
public class UserManagerBean implements Serializable{...}

and i will access some fields from a other bean. How can i do this?

Thank you

Was it helpful?

Solution

You can do that by taking the bean as a @ManagedProperty of the other bean and then just access it as an usual property in the action methods.

@ManagedBean
public class OtherBean implements Serializable {

    @ManagedProperty(value="#{userManagerBean}")
    private UserManagerBean userManagerBean;

    // ...
}

It will be set directly after construction, so it wouldn't be available in the constructor. If you'd like to do some init stuff which relies on its availablility, then make use of @PostConstruct:

    @PostConstruct
    public void init() {
        userManagerBean.doStuff();
        // ...
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top