views:

58

answers:

1

Hello, 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

+1  A: 

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();
        // ...
    }
BalusC
Thank you this work perfect. For all other People: You need a setter and getter for the userManagerBean in this example.
ThreeFingerMark
That's just obvious :) It's after all a **javabean**.
BalusC