i think what you need is onbeforerender() and not oninintialize, before rendering visibility is determined( if curious check the source in component#internalbeforer()) , also i am assuming when you will create/add 100 labels,you will use a repeater like dataview/listview which creates and adds items in onbeforerender so if your repeater is not visible, the items/children (and your labels) will not be created/rendered ...
On Mon, Dec 16, 2013 at 7:26 PM, Decebal Suiu <decebal.s...@asf.ro> wrote: > Hi > > First, the scenario (a simplified version): > I have a XPage (extends WebPage) and in the constructor of this page I want > to add a YPanel (extends Panel) but depending on a condition. > > if (condiiton) { > add(new YPanel("panel")); > } else { > add(new WebMarkupContainer("panel").setVisible(false)); > } > > In fact my scneario is a little complicated, with four children (a CartPage > that contains EmptyLabel, CartPanel, LoginPanel, CheckputPanel) and a > compund condition (isEmptyCart, isUserLogged) and in this situation my code > is verbose and a little spaghetti. > > The code above resolves my scenario but in my opinion is more readable only > a single line > > add(new YPanel("panel").setVisible(condition)); > > The solution with a single line is more readable but it has an impediment. > For example if in YPanel I want to add 100 labels (hypothetically), I > created 100 label only to add nothing if the condition is not satisfied :) > > The solution is to have a slim constructor for YPanel and to add the > children in a method (something like onInitialize) that depends on > component > visibility. I want something like "I know that this component is invisible > so don't bother to create the children". > > I know about the request cycle (not in details) and that it's impossible > for > now, I know that my "issue" is a philosophical issue but maybe someone has > a > good question. > > Best regards, > Decebal > > > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/a-little-question-about-add-new-XComponent-id-setVisible-false-tp4663041.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 > > -- regards, Vineet Semwal