문제

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

도움이 되었습니까?

해결책

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();
        // ...
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top