Vaadin - 如果我使用AbsoluteLayout,则不显示表数据

Bra*_*zic 3 java vaadin vaadin7

目前我面临着与Vaadin Table相当奇怪的问题.如果我在表中使用AbsoluteLayout数据没有显示,但如果我使用ie Horizo​​ntalLayout,数据就会完美显示.这有效:

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;

public class MyComposite extends CustomComponent {


    @AutoGenerated
    private HorizontalLayout mainLayout;
    @AutoGenerated
    private Table table;


    public MyComposite() {
        buildMainLayout();
        setCompositionRoot(mainLayout);
        // TODO add user code here

        table.addContainerProperty("First Name", String.class, null);
        table.addContainerProperty("Last Name", String.class, null);
        table.addContainerProperty("Year", Integer.class, null);

        table.addItem(new Object[] { "Nicolaus", "Copernicus",
                new Integer(1473) }, new Integer(1));
        table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) },
                new Integer(2));

    }

    @AutoGenerated
    private HorizontalLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new HorizontalLayout();
        mainLayout.setStyleName("blue");
        mainLayout.setImmediate(false);
        mainLayout.setWidth("100%");
        mainLayout.setHeight("100%");
        mainLayout.setMargin(false);

        // top-level component properties
        setWidth("100.0%");
        setHeight("100.0%");

        // table
        table = new Table();
        table.setImmediate(false);
        table.setWidth("100.0%");
        table.setHeight("100.0%");
        mainLayout.addComponent(table);

        return mainLayout;
    }

}
Run Code Online (Sandbox Code Playgroud)

但这不是:

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Table;

public class MyComposite extends CustomComponent {


    @AutoGenerated
    private AbsoluteLayout mainLayout;
    @AutoGenerated
    private Table table;
    public MyComposite() {
        buildMainLayout();
        setCompositionRoot(mainLayout);
        // TODO add user code here

        table.addContainerProperty("First Name", String.class, null);
        table.addContainerProperty("Last Name", String.class, null);
        table.addContainerProperty("Year", Integer.class, null);

        table.addItem(new Object[] { "Nicolaus", "Copernicus",
                new Integer(1473) }, new Integer(1));
        table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) },
                new Integer(2));

    }

    @AutoGenerated
    private AbsoluteLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new AbsoluteLayout();
        mainLayout.setStyleName("blue");
        mainLayout.setImmediate(false);
        mainLayout.setWidth("100%");
        mainLayout.setHeight("100%");

        // top-level component properties
        setWidth("100.0%");
        setHeight("100.0%");

        // table
        table = new Table();
        table.setImmediate(false);
        table.setWidth("100.0%");
        table.setHeight("100.0%");
        mainLayout.addComponent(table);

        return mainLayout;
    }

}
Run Code Online (Sandbox Code Playgroud)

两种情况都显示列的名称.有人能告诉我为什么会这样吗?提前致谢.

pap*_*ito 5

我能够重现你的问题.似乎Vaadin的家伙在这里描述了原因: Vaadin的书

引用:

包含百分比大小的组件的布局必须具有已定义的大小!

如果布局具有未定义的大小并且包含的​​组件具有100%大小,则组件将尝试填充布局给出的空间,而布局将缩小以适合组件占用的空间,这是一个悖论.此要求分别适用于高度和宽度.调试模式允许检测这种无效情况; 请参见第11.3.5节"检查组件层次结构"

在AbsoluteLayout的情况下,到目前为止我找到的唯一解决方法是将表格尺寸设置为某个固定值.