JSF 2.0: Why is the JSF bean created when it is used in a component that is not displayed?

Suppose it has an extremely simple composite component:

<cc:implementation>
    #{testBean.someField}
</cc:implementation>

Bean for him:

public class TestBean {

    private boolean someField = false;
    public boolean getSomeField() { return someField; }

    @PostConstruct
    public void init() {
        System.out.println("PostConstruct");
    }

}

Then call it as usual, but do not show it:

<codeEditor:test rendered="#{false}" />

It happens that the component is never displayed, and the bean never starts, as one might assume.

However, if we change the component as:

<cc:implementation>
    <h:outputText value="#{testBean.someField}" />
</cc:implementation>

What happens is that the component is still never processed (because the attribute rendered false), however the bean gets an instance. This is what always happens when we use a bean property within a certain built-in JSF component ( h:panelGroup, h:inputHidden, whatever).

Why is this so?

+3
1

( beans) . rendered . JSF.

bean , , rendered.

+6

Source: https://habr.com/ru/post/1775619/