Java FormComponents具有通用的isVisible方法
有没有办法让几个不同的wicket组件具有相同的isVisible()实现 例如,我有标签、文本字段、下拉选项等等,它们都有相同的isVisible方法,但我不习惯为它们实现自定义类,因为很难维护对代码的更改 顺便说一句,由于页面的设计原因,我不能将它们放在webmarkupcontainer中 我希望他们都能继承这样的东西Java FormComponents具有通用的isVisible方法,java,wicket,Java,Wicket,有没有办法让几个不同的wicket组件具有相同的isVisible()实现 例如,我有标签、文本字段、下拉选项等等,它们都有相同的isVisible方法,但我不习惯为它们实现自定义类,因为很难维护对代码的更改 顺便说一句,由于页面的设计原因,我不能将它们放在webmarkupcontainer中 我希望他们都能继承这样的东西 public class DepositoryFormComponent extends Component { public DepositoryFormComponen
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(){};
}您有几个选择:
WebMarkupContainer
IBehavior
,它将计算可见性,并在组件上调用setVisible()
。如果不希望以后调用setVisible()
来改变组件的可见性,也可以调用。可能不完全像覆盖是可见的
,但我认为如果不创建自定义组件,就不太可能实现覆盖
public class VisiblityControlBehavior extends AbstractBehavior {
private boolean isComponentVisible() {
return isFormDepositoryType();
}
protected boolean isFormDepositoryType() {
return getCurrentSelections().getSelectedOwnedAccount().getAssetType() == AssetType.DEPOSITORY;
}
protected CurrentSelections getCurrentSelections() {
return (CurrentSelections) getSession().getAttribute(CurrentSelections.ATTRIBUTE_NAME);
}
@Override
public void bind(Component component) {
boolean visible = isComponentVisible();
component.setVisible(visible);
component.setVisibilityAllowed(visible);
}
}