vaadin table is not displaying

I tried below code.but it’s not displaying any data in the browser.please help me to resolve this.

package com.example.testproject1;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.data.Item;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;

import com.vaadin.ui.Table;

import com.vaadin.ui.UI;

@SuppressWarnings(“serial”)
@Theme(“testproject1”)
public class Testproject1UI extends UI {

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

@Override
protected void init(VaadinRequest request) {


    Table table = new Table("Patient Data");
    
    table.addContainerProperty("Name", String.class, null);
    table.addContainerProperty("Location", String.class, null);
    table.addContainerProperty("SSN", String.class, null);
    table.addContainerProperty("Age",Integer.class , null);
    // Add a few other rows using shorthand addItem()
    Item item = table.addItem("TIM");
    item.getItemProperty("Name").setValue("Tim");
    item.getItemProperty("Location").setValue("room 453");
    item.getItemProperty("SSN").setValue("2343-654");
    item.getItemProperty("Age").setValue(new Integer(21));

    // Show exactly the currently contained rows (items)
    table.setPageLength(table.size());
    table.setVisible(true);
}

}

Hi,

you’re not adding the Table to the UI or any layout in your code. Try adding e.g. setContent(table); into your init method. Could be that you need some sizing or a layout too, depending on your needs.

-tepi

that’ work…thank you :slight_smile: