0
我有一个由两个子组件A和B组成的组件。但是,显示A或B的可见性只能在页面呈现开始后才能确定。我想这样做,但回来以下错误:在渲染开始后更改子组件的可见性
Cannot modify component hierarchy after render phase has started
那么,有没有什么办法改变我的情况下,子组件的知名度?
我有一个由两个子组件A和B组成的组件。但是,显示A或B的可见性只能在页面呈现开始后才能确定。我想这样做,但回来以下错误:在渲染开始后更改子组件的可见性
Cannot modify component hierarchy after render phase has started
那么,有没有什么办法改变我的情况下,子组件的知名度?
我不完全确定我是否了解您的问题。 我假设你有2个容器,并且只想显示其中的一个。如果是这种情况,您可以简单地扩展onConfigure()
方法并按照您希望的方式更改可见性。此方法在每次渲染过程中将被调用一次,因此优先于扩展isVisible()
方法(在每个请求期间多次调用该方法)。
private IModel<Boolean> switchModel = Model.of(Boolean.FALSE);
@Override
protected void onInitialize() {
super.onInitialize();
WebMarkupContainer container1 = new WebMarkupContainer("container1") {
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(Boolean.TRUE.equals(switchModel.getModelObject()));
}
};
add(container1);
WebMarkupContainer container2 = new WebMarkupContainer("container2") {
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(Boolean.FALSE.equals(switchModel.getModelObject()));
}
};
add(container2);
}