views:

68

answers:

1

Hello,

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

+1  A: 

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);
    }
}
BalusC
Is it the 'standard' way to initialize? :)
l245c4l
@l245c4l: If the constructor is not sufficient ("too early") due to managed dependencies, then yes. @Pascal: It will. There the annotation is for.
BalusC
Thanks again, so I should catch(Exception e) and throw RuntimeExcpetion(e)?
l245c4l
For example. I however prefer to be a bit more specific, so that bugs are spotted earlier.
BalusC