Hi,
I think I just responded to you in your own thread - where I didn't know
what you were trying to do. I still don't claim to fully understand, but I
think I better understand your question here. If you mean that you have
one panel that *may possibly contain any one of X panels*, then here's one
solution:
ContainingPanel.html:
<wicket:panel>
Some markup here
Blah, blah, blah...
<div wicket:id="childPanel"></div>
More surrounding markup...
</wicket:panel>
ContainingPanel.java:
class ContainingPanel extends Panel {
public void onBeforeRender() {
if(getModelObject() is of some type) {
addOrReplace(new SomePanel("childPanel"));
} else if(getModelObject() is of some other type) {
addOrReplace(new SomeOtherPanel("childPanel"));
}
}
}
You only need one wicket:id in your containing panel. You just swap at
runtime which component actually shows up in that spot.
I did almost exactly as Jeremy mentioned. Here is what I use:
public void onBeforeRender() {
Component component = get("childPanel");
if(getModelObject() is of some type) {
if(component instanceof SomePanel == false)
addOrReplace(new SomePanel("childPanel"));
} else if(getModelObject() is of some other type) {
if(component instanceof SomeOtherPanel == false)
addOrReplace(new SomeOtherPanel("childPanel"));
}
}
As you can see, the difference is that I don't replace the component if
it's already of the correct type. This is important if SomePanel or
SomeOtherPanel contains state. Without my modifications, when the parent
container is rendered, the child panels will always be reset to its
initial state.
Bertrand
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]