使用Vaadin 7.3.10。
我在面板中添加了一个布局组件 如果需要,布局应滚动。
但是当我尝试更换布局组件时,新的 组件添加(如下所示)而不是替换 现有组件 - 请参阅下面的代码示例。
如何/可以这样做?
n.b。如果布局不包含在面板内,则 替换发生正确。 此外,我不需要使用导航器。
谢谢你, 史蒂夫...
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
public class NewComponent extends VerticalLayout {
private VerticalLayout mainLayout = new VerticalLayout();
private Panel panel = new Panel();
public NewComponent() {
mainLayout.addComponent(new Label("Main"));
mainLayout.setSizeFull();
addComponent(mainLayout);
panel.setWidth("1000px");
panel.setHeight("500px");
panel.setContent(mainLayout);
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
replaceComponent(mainLayout, new Label("what's wrong?"));
}
});
mainLayout.addComponent(button);
addComponent(panel);
}
}
public class TestUI extends UI {
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = TestUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
setContent(new NewComponent());
}
答案 0 :(得分:1)
您必须在replaceComponent
上打电话{/ 1}} ,而打电话。
现在它看起来像这样:
mainLayout
然后你在newComponent上调用<newComponent>
<panel>
<mainLayout>
<labelMain/>
<clickMeButton/>
</mainLayout>
</panel>
</newComponent>
,这将添加像这样的标签
replaceComponent
应该看起来像这样:
<newComponent>
<panel>
<mainLayout>
<labelMain/>
<clickMeButton/>
</mainLayout>
</panel>
<whatsWrongLabel/>
</newComponent>
然后<newComponent>
<panel>
<mainLayout>
<labelMain/>
</mainLayout>
</panel>
<clickMeButton/>
</newComponent>
。
答案 1 :(得分:1)
mainLayout不在VerticalLayout中,这就是为什么只是添加新组件。您必须替换面板的内容。
更改
replaceComponent(mainLayout, new Label("what's wrong?"));
要
panel.setContent(new Label("what's wrong?"));