? equals = myPojoProviderService.getAllMyPojos()

model

package com.dataSQL.basic;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Product {

    private int id;    
    private String small_desc;
    private String large_desc;
    private String sku;
    private String category;
    private String barcode;    
    
    public Product() {
    }
    
    public Product(int id, String small_desc, String large_desc, String sku, String category, String barcode) {            
        this.id = id;        
        this.small_desc = small_desc;
        this.large_desc = large_desc;        
        this.sku = sku;
        this.category = category;
        this.barcode = barcode;         
    }
        
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSmall_desc() {
        return small_desc;
    }

    public void setSmall_desc(String small_desc) {
        this.small_desc = small_desc;
    }

    public String getLarge_desc() {
        return large_desc;
    }

    public void setLarge_desc(String large_desc) {
        this.large_desc = large_desc;
    }

    public String getSku() {
        return sku;
    }

    public void setSku(String sku) {
        this.sku = sku;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    @Override
    public String toString() {
        return "Product [id=" + id                
                + ", small_desc=" + small_desc
                + ", large_desc=" + large_desc                
                + ", sku=" + sku
                + ", category=" + category                
                + ", barcode=" + barcode + "]";
    }

}


Controller

package com.dataSQL.basic;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class ProductController {

    private List<Product> products;
    private ProductDbUtil productDbUtil;
    private Logger logger = Logger.getLogger(getClass().getName());
    
    public ProductController() throws Exception {
        products = new ArrayList<>();
        
        productDbUtil = ProductDbUtil.getInstance();
    }
    
    public List<Product> getProducts() {
        return products;
    }

    public void loadProducts() {

        logger.info("Loading products");
        
        products.clear();

        try {
            
            // get all products from database
            products = productDbUtil.getProducts();
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
        }
    }
        
    public String addProduct(Product theProduct) {

        logger.info("Adding product: " + theProduct);

        try {
            
            // add product to the database
            productDbUtil.addProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error adding products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);

            return null;
        }
        
        return "list-products?faces-redirect=true";
    }

    public String loadProduct(int productId) {
        
        logger.info("loading product: " + productId);
        
        try {
            // get product from database
            Product theProduct = productDbUtil.getProduct(productId);
            
            // put in the request attribute ... so we can use it on the form page
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();        

            Map<String, Object> requestMap = externalContext.getRequestMap();
            requestMap.put("product", theProduct);    
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading product id:" + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
                
        return "update-product-form.xhtml";
    }    
    
    public String updateProduct(Product theProduct) {

        logger.info("updating product: " + theProduct);
        
        try {
            
            // update product in the database
            productDbUtil.updateProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error updating product: " + theProduct, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products?faces-redirect=true";        
    }
    
    public String deleteProduct(int productId) {

        logger.info("Deleting product id: " + productId);
        
        try {

            // delete the product from the database
            productDbUtil.deleteProduct(productId);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error deleting product id: " + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products";    
    }    
    
    private void addErrorMessage(Exception exc) {
        FacesMessage message = new FacesMessage("Error: " + exc.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
}
[/code]DAO


[code]
package com.dataSQL.basic;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ProductDbUtil {

    private static ProductDbUtil instance;
    private DataSource dataSource;
    private String jndiName = "java:comp/env/jdbc/webdata";
    
    public static ProductDbUtil getInstance() throws Exception {
        if (instance == null) {
            instance = new ProductDbUtil();
        }
        
        return instance;
    }
    
    private ProductDbUtil() throws Exception {        
        dataSource = getDataSource();
    }

    private DataSource getDataSource() throws NamingException {
        Context context = new InitialContext();
        
        DataSource theDataSource = (DataSource) context.lookup(jndiName);
        
        return theDataSource;
    }
        
    public List<Product> getProducts() throws Exception {

        List<Product> products = new ArrayList<>();

        Connection myConn = null;
        Statement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product order by category";

            myStmt = myConn.createStatement();

            myRs = myStmt.executeQuery(sql);

            // process result set
            while (myRs.next()) {
                
                // retrieve data from result set row
                int id = myRs.getInt("id");                            
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");
                String sku = myRs.getString("sku");                
                String category = myRs.getString("category");
                String barcode = myRs.getString("barcode");                
                

                // create new product object
                Product tempProduct = new Product(id, small_desc, large_desc, sku, category, barcode);

                // add it to the list of products
                products.add(tempProduct);
            }
            
            return products;        
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }

    public void addProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "insert into product (small_desc, large_desc, sku, category, barcode) values (?, ?, ?, ?, ?)";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();            
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public Product getProduct(int productId) throws Exception {
    
        Connection myConn = null;
        PreparedStatement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product where id=?";

            myStmt = myConn.prepareStatement(sql);
            
            // set params
            myStmt.setInt(1, productId);
            
            myRs = myStmt.executeQuery();

            Product theProduct = null;
            
            // retrieve data from result set row
            if (myRs.next()) {
                int id = myRs.getInt("id");
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");                
                String sku = myRs.getString("sku");
                String category = myRs.getString("category");                
                String barcode = myRs.getString("barcode");                

                theProduct = new Product(id, small_desc, large_desc, sku, category, barcode);
            }
            else {
                throw new Exception("Could not find product id: " + productId);
            }

            return theProduct;
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }
    
    public void updateProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "update product "
                        + " set small_desc=?, large_desc=?, sku=?, category=?, barcode=?"
                        + " where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params            
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public void deleteProduct(int productId) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "delete from product where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setInt(1, productId);
            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }        
    }    
    
    private Connection getConnection() throws Exception {

        Connection theConn = dataSource.getConnection();
        
        return theConn;
    }
    
    private void close(Connection theConn, Statement theStmt) {
        close(theConn, theStmt, null);
    }
    
    private void close(Connection theConn, Statement theStmt, ResultSet theRs) {

        try {
            if (theRs != null) {
                theRs.close();
            }

            if (theStmt != null) {
                theStmt.close();
            }

            if (theConn != null) {
                theConn.close();
            }
            
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }    
}
[/code]
Vaadin 8 Archetype MainUI.java[code]
package com.dataSQL.basic;

import java.util.List;
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.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        List<Product> products = ProductDbUtil.getProducts();
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

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

32006.png

In the MainUI init() method, have you tried

List products = ProductDbUtil.getInstance().getProducts();

?

Hello, sorry for the tardy response.

Shall try now.

did not work…

Multiple markers at this line
- Unhandled exception type Exception
- Unhandled exception type Exception

31912.png
31913.png

model

package com.dataSQL.basic;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Product {

    private int id;    
    private String small_desc;
    private String large_desc;
    private String sku;
    private String category;
    private String barcode;    
    
    public Product() {
    }
    
    public Product(int id, String small_desc, String large_desc, String sku, String category, String barcode) {            
        this.id = id;        
        this.small_desc = small_desc;
        this.large_desc = large_desc;        
        this.sku = sku;
        this.category = category;
        this.barcode = barcode;         
    }
        
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getSmall_desc() {
        return small_desc;
    }

    public void setSmall_desc(String small_desc) {
        this.small_desc = small_desc;
    }

    public String getLarge_desc() {
        return large_desc;
    }

    public void setLarge_desc(String large_desc) {
        this.large_desc = large_desc;
    }

    public String getSku() {
        return sku;
    }

    public void setSku(String sku) {
        this.sku = sku;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    @Override
    public String toString() {
        return "Product [id=" + id                
                + ", small_desc=" + small_desc
                + ", large_desc=" + large_desc                
                + ", sku=" + sku
                + ", category=" + category                
                + ", barcode=" + barcode + "]";
    }

}


Controller

package com.dataSQL.basic;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class ProductController {

    private List<Product> products;
    private ProductDbUtil productDbUtil;
    private Logger logger = Logger.getLogger(getClass().getName());
    
    public ProductController() throws Exception {
        products = new ArrayList<>();
        
        productDbUtil = ProductDbUtil.getInstance();
    }
    
    public List<Product> getProducts() {
        return products;
    }

    public void loadProducts() {

        logger.info("Loading products");
        
        products.clear();

        try {
            
            // get all products from database
            products = productDbUtil.getProducts();
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
        }
    }
        
    public String addProduct(Product theProduct) {

        logger.info("Adding product: " + theProduct);

        try {
            
            // add product to the database
            productDbUtil.addProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error adding products", exc);
            
            // add error message for JSF page
            addErrorMessage(exc);

            return null;
        }
        
        return "list-products?faces-redirect=true";
    }

    public String loadProduct(int productId) {
        
        logger.info("loading product: " + productId);
        
        try {
            // get product from database
            Product theProduct = productDbUtil.getProduct(productId);
            
            // put in the request attribute ... so we can use it on the form page
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();        

            Map<String, Object> requestMap = externalContext.getRequestMap();
            requestMap.put("product", theProduct);    
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error loading product id:" + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
                
        return "update-product-form.xhtml";
    }    
    
    public String updateProduct(Product theProduct) {

        logger.info("updating product: " + theProduct);
        
        try {
            
            // update product in the database
            productDbUtil.updateProduct(theProduct);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error updating product: " + theProduct, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products?faces-redirect=true";        
    }
    
    public String deleteProduct(int productId) {

        logger.info("Deleting product id: " + productId);
        
        try {

            // delete the product from the database
            productDbUtil.deleteProduct(productId);
            
        } catch (Exception exc) {
            // send this to server logs
            logger.log(Level.SEVERE, "Error deleting product id: " + productId, exc);
            
            // add error message for JSF page
            addErrorMessage(exc);
            
            return null;
        }
        
        return "list-products";    
    }    
    
    private void addErrorMessage(Exception exc) {
        FacesMessage message = new FacesMessage("Error: " + exc.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
}
[/code]DAO


[code]
package com.dataSQL.basic;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class ProductDbUtil {

    private static ProductDbUtil instance;
    private DataSource dataSource;
    private String jndiName = "java:comp/env/jdbc/webdata";
    
    public static ProductDbUtil getInstance() throws Exception {
        if (instance == null) {
            instance = new ProductDbUtil();
        }
        
        return instance;
    }
    
    private ProductDbUtil() throws Exception {        
        dataSource = getDataSource();
    }

    private DataSource getDataSource() throws NamingException {
        Context context = new InitialContext();
        
        DataSource theDataSource = (DataSource) context.lookup(jndiName);
        
        return theDataSource;
    }
        
    public List<Product> getProducts() throws Exception {

        List<Product> products = new ArrayList<>();

        Connection myConn = null;
        Statement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product order by category";

            myStmt = myConn.createStatement();

            myRs = myStmt.executeQuery(sql);

            // process result set
            while (myRs.next()) {
                
                // retrieve data from result set row
                int id = myRs.getInt("id");                            
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");
                String sku = myRs.getString("sku");                
                String category = myRs.getString("category");
                String barcode = myRs.getString("barcode");                
                

                // create new product object
                Product tempProduct = new Product(id, small_desc, large_desc, sku, category, barcode);

                // add it to the list of products
                products.add(tempProduct);
            }
            
            return products;        
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }

    public void addProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "insert into product (small_desc, large_desc, sku, category, barcode) values (?, ?, ?, ?, ?)";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();            
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public Product getProduct(int productId) throws Exception {
    
        Connection myConn = null;
        PreparedStatement myStmt = null;
        ResultSet myRs = null;
        
        try {
            myConn = getConnection();

            String sql = "select * from product where id=?";

            myStmt = myConn.prepareStatement(sql);
            
            // set params
            myStmt.setInt(1, productId);
            
            myRs = myStmt.executeQuery();

            Product theProduct = null;
            
            // retrieve data from result set row
            if (myRs.next()) {
                int id = myRs.getInt("id");
                String small_desc = myRs.getString("small_desc");
                String large_desc = myRs.getString("large_desc");                
                String sku = myRs.getString("sku");
                String category = myRs.getString("category");                
                String barcode = myRs.getString("barcode");                

                theProduct = new Product(id, small_desc, large_desc, sku, category, barcode);
            }
            else {
                throw new Exception("Could not find product id: " + productId);
            }

            return theProduct;
        }
        finally {
            close (myConn, myStmt, myRs);
        }
    }
    
    public void updateProduct(Product theProduct) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "update product "
                        + " set small_desc=?, large_desc=?, sku=?, category=?, barcode=?"
                        + " where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params            
            myStmt.setString(1, theProduct.getSmall_desc());
            myStmt.setString(2, theProduct.getLarge_desc());
            myStmt.setString(3, theProduct.getSku());
            myStmt.setString(4, theProduct.getCategory());
            myStmt.setString(5, theProduct.getBarcode());            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }
        
    }
    
    public void deleteProduct(int productId) throws Exception {

        Connection myConn = null;
        PreparedStatement myStmt = null;

        try {
            myConn = getConnection();

            String sql = "delete from product where id=?";

            myStmt = myConn.prepareStatement(sql);

            // set params
            myStmt.setInt(1, productId);
            
            myStmt.execute();
        }
        finally {
            close (myConn, myStmt);
        }        
    }    
    
    private Connection getConnection() throws Exception {

        Connection theConn = dataSource.getConnection();
        
        return theConn;
    }
    
    private void close(Connection theConn, Statement theStmt) {
        close(theConn, theStmt, null);
    }
    
    private void close(Connection theConn, Statement theStmt, ResultSet theRs) {

        try {
            if (theRs != null) {
                theRs.close();
            }

            if (theStmt != null) {
                theStmt.close();
            }

            if (theConn != null) {
                theConn.close();
            }
            
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }    
}
[/code]
Vaadin 8 Archetype MainUI.java[code]
package com.dataSQL.basic;

import java.util.List;
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.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        List<Product> products = ProductDbUtil.getProducts();
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

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

Wrap it in a
try-catch block
. You can also have Eclipse do it for you by hitting F2 with the cursor over the code with the red squiggly line.

Are you well acquainted with Java fundamentals? If not, and given that you are considering taking courses, I think it would be worthwhile to get the rudiments down solid. Creating instances and handling exceptions are common Java operations, and it would reduce the number of round trips when you are asking for help on these forums. It will also help you to better understand the code examples given on the
blog posts that you have referenced
. The post is actually quite self-explanatory, however the sample is not meant to be cut-and-pasted into your IDE; the writer expects the reader to adapt it to their own environment.

Just a suggestion.

– AC

Shall be taking Java course to expand upon all that you have shared with me.

I found the solution, but do not know how to implement it

You need to create an instance of the object first using the “new” keyword, then call the method.

but do not know how to implement it to the following code:

[code]
package com.dataSQL.basic;

import java.util.List;
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.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {  
        
        
        List<Product> products = ProductDbUtil.getProducts();
        
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);        
    }

    @WebServlet(urlPatterns = "/*", name = "MainUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MainUI.class, productionMode = false)
    public static class MainUIServlet extends VaadinServlet {
    }
}
[/code]

31915.png

You don’t need to use “new” because it’s done for you in the getInstance() factory method. As I mentioned in the previous post, wrap the line in a try-catch block.

List<Product> products;
try{
    products = ProductDbUtil.getInstance().getProducts();
} catch (Exception e) {
}

Grid<Product> grid = new Grid<>(Product.class);
grid.setItems(products);

trying right now!

Excellent, thank you.

The local variable products may not have been initialized
31916.png

ok, I applied quick fix
and it has no errors but still does not display the grid

one moment shall make a video note

Below is the code

package com.dataSQL.basic;

import java.util.List;
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.Grid;
import com.vaadin.ui.UI;

@Theme("maintheme")
public class MainUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {        
        List<Product> products = null;
        try{
            products = ProductDbUtil.getInstance().getProducts();
        } catch (Exception e) {
        }
        Grid<Product> grid = new Grid<>(Product.class);
        grid.setItems(products);     
    }
    @WebServlet(urlPatterns = "/*", name = "MainUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MainUI.class, productionMode = false)
    public static class MainUIServlet extends VaadinServlet {
    }
}

do I have to put in the layout?

video notes
https://www.useloom.com/share/124a632267b143e683045e56cbd3edf1

Shall try again.

Your Jetty server is not starting cleanly, it throws several exceptions because it can’t resolve jdbc/webdata. As I mentioned in an earlier post, you need to have a WebContent folder that is mapped to / in the deployment assembly. This folder can be created for you by adding the Dynamic Web Module facet. In that folder are WEB-INF and a META-INF, which are the locations for your xml configuration files.

Also, you never attach the grid (or anything) to the UI (
docs here
).

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        try{
            List<Product> products = ProductDbUtil.getInstance().getProducts();
            Grid<Product> grid = new Grid<>(Product.class);
            grid.setItems(products);
            setContent(grid);
        } catch (Exception e) { }
    }

– AC

Excellent!

I have a WebContent folder that was created by adding the Dynamic Web Module facet, and I have both WEB-INF and META-INF folder which has the xml configuration files:

Context.xml
Web.xml

I followed your instructions – and shall double check here again:

If you have m2e and m2e-wtp installed in Eclipse, then you can add the Dynamic Web Module facet to your Vaadin archetype project (right click your project, select Properties, choose Project Facets from the left pane). If your project is not already in faceted form, converting it and adding Dynamic Web Module will give you a WebContent folder with a WEB-INF and a META-INF, so you now have a destination for your web.xml and context.xml.

Your deployment assembly (also under project properties) must include the following mappings:

/WebContent => /
/src/main/webapp => /
Maven Dependencies => WEB-INF/lib

I’ve attached an image that shows you the mappings I have for one of my projects that deploys to a server (instead of using the jetty-maven plugin). Note the options in the “New Assembly Directive” dialog box. If you don’t see these options (e.g. Java Build Path Entries), then make sure m2e and m2e-wtp are installed correctly.

Finally, I recommend making your mysql jdbc connector 5.1.40 a maven dependency instead of a referenced library. You can do that by adding the following lines to your pom.xml in the section:

12345

mysql
mysql-connector-java
5.1.40

It WORKED!

I have a VAADIN GRID populated with remote data!

Jetty did not run, HTTP ERROR: 503
Problem accessing /. Reason:Service UnavailablePowered by Jetty:// 9.3.9.v20160517

But it ran locally using Tomcat

video notes:
https://www.useloom.com/share/5e22c850dac8425a8b412ec49e5554e4

Congrats! Pop the champagne!

Final thoughts from your video post:

  1. Adding project

    facets

    in Eclipse is not the same as "Java Server

    Faces

    " or JSF. Totally different. All the same, you got it working.
  2. There is no error in the app. The reason that there is nothing to the right of the grid is because you don’t have any code that puts anything to the right of the grid. All you have is a UI subclass that takes a grid. To get the rest, take the code from a working example and merge that into your init() method on your UI class.

Best of luck.

– AC