Is there someway i can have several different wicket components have the same implementation of isVisible()
for instance i have Labels, TextFields, DropdownChoices and etc that have the same isVisible method but i dont wont to implement custom classes for all of them since is hard to maintain changes to the code.
btw i can’t put them in a webmarkupcontainer due to the design of the page.
I want them all to inherit something like this.
public class DepositoryFormComponent extends Component
{
public DepositoryFormComponent(String id) {
super(id);
}
public DepositoryFormComponent(String id, IModel model) {
super(id, model);
}
public boolean isVisible() {
return isFormDepositoryType();
}
protected boolean isFormDepositoryType() {
return getCurrentSelections().getSelectedOwnedAccount().getAssetType() == AssetType.DEPOSITORY;
}
protected CurrentSelections getCurrentSelections() {
return (CurrentSelections) getSession().getAttribute(CurrentSelections.ATTRIBUTE_NAME);
}
public void onRender(){};
}
You have several options:
If you’ve got control over the markup, and can group in a single tag all the components you want to control visibility of, you could use a
<wicket:enclosure>tag to make a Component control visibility of an entire piece of markup. Notice this won’t affect page design, and would achieve a similar effect as to adding aWebMarkupContainerYou could add to those components an
IBehaviorthat will calculate visibility and callsetVisible()on theComponent. You can also invokeComponent#setVisibilityAllowed()if you don’t want future calls tosetVisible()to alter theComponent‘s visibilty. Maybe not exactly as overridingisVisible, but I think it’ll be unlikely to achieve an override if you don’t create custom components.