0

I have a DAO that returns some informations of my database. I want show thats informations in a table but doesn't work. The informations not displayed.

I'm trying this.

//DAO
public class CustomerDAO {
     private Connection con = connection.getConnection();
     public List<Customer> getCustomer(){
          List<Customer> list = new ArrayList<Customer>();
          PreparedStatement stm = this.con.prepareStatement("SELECT * FROM customer");
          ResultSet rs = stm.executeQuery();
          while(rs.next()){
               Customer c = new Customer();
               c.setName(rs.getString("name"));
               list.add(c);
          }
          return list;
     }
}

// customer view
public class CustomerView extends CustomComponents{
     private Table table;
     private List<Customer> list;

     public CustomerView(){
          table = new Table();
          table.setSizeFull();
          tabela.addContainerProperty("Customer", String.class, null);
          getCustomer();
     }

     /** populate table */
     private void getCustomer(){
        list = new CustomerDAO().getCustomer();
        if(!list.isEmpty()){
            for(Customer c : list){
                 table.addItem(new Object[]{c.getName()}, 1);
            } 
        }
     }
}

Any idea ?

FernandoPaiva
  • 4,410
  • 13
  • 59
  • 118

1 Answers1

0

Your getCustomer() method is not quite right implemented.

Try:

private void getCustomer() {
    list = new CustomerDAO().getCustomer();
    if(!list.isEmpty()){
        for(Customer c : list){
             table.addItem(new Object[] { c.getName() }, null);
        } 
    }
 }

You can find the method description here.

another solution:

private void getCustomer() {
    list = new CustomerDAO().getCustomer();
    if(!list.isEmpty()){
        for(Customer c : list){
            Object addItem = table.addItem();
            table.getItem(addItem).getItemProperty("Customer").setValue(c.getName());
        } 
    }
 }
nexus
  • 2,937
  • 3
  • 17
  • 22