I think it's fine to change the hierarchy in onBeforeRender(), as long as you do it before calling super.onBeforeRender(), since that calls OBR on the children of your panel. And (you gotta love wicket), this is even made explicit in the source code of MarkupContainer#onBeforeRender():

/**
     * Called just before a component is rendered.
     * <p>
* <strong>NOTE</strong>: If you override this, you *must* call super.onBeforeRender() within
     * your implementation.
     *
* Because this method is responsible for cascading {@link #onBeforeRender()} call to its * children it is strongly recommended that super call is made at the end of the override.
     * </p>
     */

Before we had onInitialize, we would use onBeforeRender() and a boolean guard variable (boolean initialized) to accomplish the same thing.

Conclusion, it's fine, as long as you call super.onBeforeRender() at the end of your method.

Met vriendelijke groet,
Kind regards,

Bas Gooren

schreef Decebal Suiu op 16-12-2013 16:50:
I tested with:

public class MyPanel extends Panel {

        public MyPanel(String id) {
                super(id);              
        }

         @Override
         protected void onBeforeRender() {
                super.onBeforeRender();
                
                add(new MyLabel("l1", "Label 1"));
                add(new MyLabel("l2", "Label 2"));
                add(new MyLabel("l3", "Label 3"));
          }

}

in MyPanel, where MyLabel extends Label with the constructor contains and
debug message:

public MyLabel(String id, String label) {
        super(id, label);
                
        System.out.println("MyLabel.MyLabel():" + id);
}

And yes, the MyLabel constructed is not called if MyPanel is not visible.

My impression was that in onBeforeRender I cannot change the hierarchy (add
children).

The 100 children was a random number that show you that my panel contains
many components :)

Thanks,
Decebal




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/a-little-question-about-add-new-XComponent-id-setVisible-false-tp4663041p4663045.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


Reply via email to