Vaadin8带有网格的错误-无法设置酸味

时间:2018-12-28 23:26:50

标签: java vaadin

我在Vaadin8 Grid中可能有一个错误-它根本不显示任何数据,也不输出任何错误。通过setData

在其中输入List <>时,它不会显示任何数据。

这是UI的代码:     @Theme(“ mytheme”)     公共类MyUI扩展了UI {

private BankeriClient bankeriClient = new BankeriClient();

@Override
protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout layout = new VerticalLayout();
    final HorizontalLayout buttonLayout = new HorizontalLayout();

    final TextField nameField = new TextField();
    final TextField surnameField = new TextField();
    final DateField dateField = new DateField();
    final TextField addressField = new TextField();
    final TextField dollarsField = new TextField();    

    Response response = bankeriClient.findAll_JSON(Response.class);
    List<Bankeri> listBankeri = response.readEntity(new GenericType<List<Bankeri>>() {});
    Grid<Bankeri> grid = new Grid<>(Bankeri.class);
    grid.addColumn(Bankeri::getJmeno).setCaption("First name").setEditorComponent(
            nameField,
            Bankeri::setJmeno
    );
    grid.addColumn(Bankeri::getPrijmeni).setCaption("Surname").setEditorComponent(
            surnameField,
            Bankeri::setPrijmeni
    );
    grid.addColumn(Bankeri::getLocalDatum_narozeni).setCaption("Date of birth").setEditorComponent(
            dateField,
            Bankeri::setLocalDatum_narozeni
    );
    grid.addColumn(Bankeri::getAdresa).setCaption("Address").setEditorComponent(
            addressField,
            Bankeri::setAdresa
    );
    grid.addColumn(Bankeri::getStringPenize).setCaption("Dollars").setEditorComponent(
            dollarsField,
            Bankeri::setStringPenize
    );
    grid.setData(listBankeri);
    grid.getEditor().setEnabled(true);
    grid.getEditor().setSaveCaption("Save");
    grid.getEditor().setCancelCaption("Cancel");

    final Button addBanker = new Button();
    addBanker.setCaption("Přidej bankéře");
    addBanker.addClickListener(e -> {
        Bankeri toAdd = new Bankeri();
        listBankeri.add(toAdd);
        grid.getDataProvider().refreshAll();
    });

    final Button saveBanker = new Button();
    saveBanker.setCaption("Ulož data bankéřů");
    saveBanker.addClickListener(e -> {
        for(Bankeri banker : listBankeri) {
            bankeriClient.create_JSON(banker);
        }
    });

    buttonLayout.addComponents(addBanker, saveBanker);
    layout.addComponents(grid, buttonLayout);

    setContent(layout);
}

@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}

关于我要显示的对象:这是一个实体类 我正在使用:GlassFish 4.1.0,netbeans。 非常感谢您的帮助!

尊敬的Jan

1 个答案:

答案 0 :(得分:0)

解决了!用setItems代替setData是正确的答案!