> cool! but aren't components instanciated in the constructor?
You don't have to keep them laying around/ create them up-front. Just
build some factory pattern, so that you'll construct them when you
need them, or at least when you have the parent instance available.
> i'll need to remove older ones, right?
> what about the constructor change in wicket 2.0?
>
You don't have to remove the components you want to replace. Just
create a new one with the same id in the same position in the
hierarchy, like is done in wicket.examples.template.TemplatePage:
...
/** the current banner. */
private Banner currentBanner;
/**
* Constructor
*/
public TemplatePage()
{
new Label(this, "title", new PropertyModel(this, "pageTitle"));
currentBanner = new Banner1(this, "ad");
new Link(this, "changeAdLink")
{
/**
* @see wicket.markup.html.link.Link#onClick()
*/
@Override
public void onClick()
{
if (currentBanner.getClass() == Banner1.class)
{
new Banner2(TemplatePage.this, "ad");
}
else
{
new Banner1(TemplatePage.this, "ad");
}
}
};
...
Alternatively, if you want to re-use instances, you can call reAttach
on a component to make sure it is the 'current one'. TemplatePage
could be rewritten like this:
public abstract class TemplatePage extends WicketExamplePage
{
/** title of the current page. */
private String pageTitle = "(no title)";
/** the current banner. */
private Banner currentBanner;
private Banner banner1;
private Banner banner2;
/**
* Constructor
*/
public TemplatePage()
{
new Label(this, "title", new PropertyModel(this, "pageTitle"));
banner2 = new Banner2(this, "ad");
currentBanner = banner1 = new Banner1(this, "ad");
new Link(this, "changeAdLink")
{
/**
* @see wicket.markup.html.link.Link#onClick()
*/
@Override
public void onClick()
{
if (currentBanner == banner1)
{
currentBanner = banner2;
banner2.reAttach();
}
else
{
currentBanner = banner1;
banner1.reAttach();
}
}
};
...
Eelco
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user