如何在Vaadin中显示网格?

时间:2016-05-05 14:10:25

标签: java vaadin

我试图在Vaadin中显示一个简单的网格,并且无法让它显示在网页上。我得到的只是一个没有错误的空白页面。谁能告诉我我做错了什么?这是我的代码:

package com.example.testyui;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
@Theme("testyui")
public class TestyUI extends UI {

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = TestyUI.class)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {

final VerticalLayout layout = new VerticalLayout();

Grid grid = new Grid("Data Grid");

layout.addComponent(grid);
grid.setSizeFull();
layout.setExpandRatio(grid, 1);

grid.addColumn("firstName");
grid.addColumn("lastName");
grid.addColumn("salary");

grid.addColumn("address.streetAddress");
grid.addColumn("address.city");
grid.addColumn("address.country");

grid.setColumnOrder("firstName", "lastName", "salary",
        "address.streetAddress", "address.city", "address.country");

grid.isImmediate();
grid.isEditorActive();
grid.setEditorEnabled(true);

grid.addRow("Gene", "Hampton", "123", "TacoRoad", "Fiesta", "USA");
grid.setVisible(true);


}

}

1 个答案:

答案 0 :(得分:1)

我认为你缺少setContent

VerticalLayout layout = new VerticalLayout();
layout.setSizeFull(); // Use entire window
setContent(layout );   // Attach to the UI

检查

https://vaadin.com/docs/-/part/framework/application/application-architecture.html