eventsjsfbindingjsf-2phaselistener

Is it possible to annotate a backing bean method to be called on a phase?


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?


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