我的Vaadin网格根本不在我的WebApp上填充

时间:2019-04-28 11:49:58

标签: java web-applications vaadin-grid

我正在使用VSCOde和Vaadin和Java来建立一个Web应用程序。 VsCode已更新,我过去使用的代码现在无法正常工作,但我不知道为什么。 “我的标签”是唯一显示根本没有填充网格的东西。

我尝试生成列,setColumns,getColumns,但是没有东西在填充它。请查看我的代码。

MainView:

enter code here

package horseRecord;

import java.util.List;

import javax.swing.text.AbstractDocument.Content;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.SelectionMode;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.server.PWA;
import com.vaadin.flow.router.Route;

@Route
@PWA(name = "EquiRecord", shortName = "EquiRecord")
public class MainView extends VerticalLayout {

    private static final long serialVersionUID = 1L;
    Connection connection = null;


    public MainView() {

        final VerticalLayout layout = new VerticalLayout();
        layout.setSizeFull();
        setContent(layout);
        Grid<Horses> grid = new Grid<>(Horses.class);

        // Database connection string
        String connectionString = "jdbc:sqlserver://equirecord.database.windows.net:1433;database=EquiRecord;user=xxxxx@equirecord;password=xxxxxxxxx;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";

        //new label
        add(new H1("EquiRecord, Recording your horses health!"), layout);

        try 
        {          
            // Connect and query the data
            connection = DriverManager.getConnection(connectionString);
            ResultSet rs = connection.createStatement().executeQuery("select * from horses;");
            // Create a list of type Student (which we defined in Student.java)
            List<Horses> horsesList = new ArrayList<Horses>();
            while(rs.next())    {
                    horsesList.add(new Horses(
                        rs.getLong("microchip"),
                        rs.getString("horseName"),
                        rs.getDate("dateOfBirth")));
                    //rs.getString("FName"),
                    //rs.getString("SName")
                }
                // Create my grid
                grid.setItems(horsesList);
                grid.addColumn(Horses::getMicrochip).setHeader("Microchip");
                grid.addColumn(Horses::getHorseName).setHeader("Horse Name");
                grid.addColumn(Horses::getDateOfBirth).setHeader("Date of Birth");
                //grid.addColumn(Horses::getFName);
                //grid.addColumn(Horses::getSName);
                //grid.setColumns("microchip", "horseName", "dateOfBirth");
                grid.setSizeFull(); 
                // This makes the grid the width of the page
                // This makes the grid 'multi-select', adds the checkboxes for selecting to the side
                grid.setSelectionMode(SelectionMode.MULTI);
            }
catch(Exception e) {
    layout.addComponentAsFirst(new Label(e.getMessage()));
}

setContent(layout);
}

    private void setContent(Object layout) {
    }


        } 

马类:

package horseRecord;

import java.sql.Date;

class Horses
{
    private Long microchip;
    private String horseName;
    private Date dateOfBirth;
    //private String FName;
    //private String SName;



    Horses(Long microchip, String horseName, Date dateOfBirth)
    {
        this.microchip = microchip;
        this.horseName = horseName;
        this.dateOfBirth = dateOfBirth;
        //this.FName = FName;
        //this.SName = SName;

    }

    public String getHorseName() {
        return horseName;
    }

    public void setHorseName(String horseName) {
        this.horseName = horseName;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateofBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public Long getMicrochip() {
        return microchip;
    }

    public void setMicrochip(Long microchip) {
        this.microchip = microchip;
    }
}

我期望一个包含三列的网格,但绝对没有显示网格,有人可以看到我在做什么吗?

感谢您提供的任何帮助。

0 个答案:

没有答案