wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Decebal Suiu <decebal.s...@asf.ro>
Subject a little question about add(new XComponent("id").setVisible(false))
Date Mon, 16 Dec 2013 13:56:36 GMT

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,

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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org

View raw message