l245c4l
l245c4l

Reputation: 4165

Problem initializing backing bean property in constructor

I have managed bean/backing bean and I inject there (with @EJB) session bean. Now in constructor I want 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

Upvotes: 0

Views: 1309

Answers (1)

BalusC
BalusC

Reputation: 1108772

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);
    }
}

Upvotes: 1

Related Questions