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

Reply via email to