Question

I need an initializer method in the backing bean to be called after components are bind. @PostConstruct is called before component bindings. Is there any JSF annotation for methods which cause method call after component binding?

Currently it's possible to use something like <f:view afterPhase="#{bean.initialize}"> or <f:event type="preRenderView" listener="#{bean.initialize}" /> which requires code on page side and bean side. Is there any bean-side-only solution?

Was it helpful?

Solution

There's nothing like that in standard JSF API.

Closest what you can get is lazy loading in getter.

public UIComponent getSomeComponent() {
    if (!initialized(someComponent)) {
        initialize(someComponent);
    }
    return someComponent;
}

or lazy executing in setter.

public void setSomeComponent(UIComponent someComponent) {
    if (!initialized(someComponent)) {
        initialize(someComponent);
    }
    this.someComponent = someComponent;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top