开发者

Problem initializing backing bean property in constructor

开发者 https://www.devze.com 2023-01-15 02:44 出处:网络
I have managed bean/backing bean and I inject there (with @EJB) session bean. Now in constructor I w开发者_开发百科ant to use it to initialize property in backing bean with value from database. But in

I have managed bean/backing bean and I inject there (with @EJB) session bean. Now in constructor I w开发者_开发百科ant to use it to initialize property in backing bean with value from database. But injected session bean is null. What are the other ways to initialize? As far as I know I can't use @PostConstruct because fetching data from database may result in exception and @PostConstruct forbids that.

Thanks in advance


You can rethrow it as an unchecked exception in @PostConstruct.

Semi-pseudo:

@PostConstruct
public void init() {
    try {
        doSomething();
    } catch (CheckedException e) {
        throw new UncheckedException(e);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消