webtier@glassfish.java.net

Constructor and the _at_PostConstruct method are excessively executed.

From: <webtier_at_javadesktop.org>
Date: Tue, 17 Aug 2010 20:30:32 PDT

In ManagedBean, the constructor and the @PostConstruct method are excessively executed.
The meaning of "excessively" is to be executed at submit in which the page doesn't change, though ManagedBean is ViewScope.

This phenomenon is generated, when ManagedBean is used with <composite:attribute>, and "required=true" is set.
When "required=true" is not set, this phenomenon is not generated.

In the following example,
when the main page is displayed, constructor and the method are executed.
In addition, when the action1 button is clicked, constructor and the method are executed again.

Is this operation correct?
I cannot consent that the phenomenon depends on "required=true".
please give advice.

-- Composite Component (useBean.xhtml) --
...
<composite:interface>
    <!-- When required is set, this phenomenon is generated. -->
    <composite:attribute name="manager" required="true"/>
    <!-- When required is not set, this phenomenon is not generated. -->
    <!-- <composite:attribute name="manager"/> -->
</composite:interface>
<composite:implementation>
    <h:outputText value="#{cc.attrs.manager.toString()}"/>
</composite:implementation>

-- Main Page (Main.xhtml) --
<ez:useBean manager="#{newManager}"/>
<!-- This button is not change page. -->
<h:commandButton action="#{newManager.action1}" value="action1"/>

-- ManagedBean Class (NewManager.java) --
@ManagedBean
@ViewScoped
public class NewManager implements Serializable {
    public NewManager() {
        System.out.println("NewManager Construct!! (" + this.toString() + ")");
    }
    @PostConstruct
    public void init() {
        System.out.println("NewManager PostConstruct!! (" + this.toString() + ")");
    }
    public void action1() {
        System.out.println("NewManager action1!! (" + this.toString() + ")");
        // This method is not change page.
    }
[Message sent by forum member 'jandoe3527']

http://forums.java.net/jive/thread.jspa?messageID=480450