Advertisement
csaffi

Vaadin Table with Checkboxes

May 5th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. myTable = new Table();
  2. myTable.addContainerProperty("c1", Boolean.class, null);
  3. myTable.setColumnCollapsed("c1", true);
  4. myTable.addGeneratedColumn("chk1", new ColumnGenerator() {
  5.  
  6.     @Override
  7.     public Object generateCell(Table source, final Object itemId, Object columnId) {
  8.         Property prop = source.getItem(itemId).getItemProperty("c1");//columnId
  9.         final CheckBox cb = new CheckBox(null, prop);
  10.         cb.setImmediate(true);
  11.         cb.addListener(new Property.ValueChangeListener() {
  12.             @Override
  13.             public void valueChange(Property.ValueChangeEvent event) {
  14.                 if (myTable.getContainerProperty(itemId, "field").getValue() != null) {
  15.                     if (!myTable.getContainerProperty(itemId, "field").getValue().equals("") && !myTable.getContainerProperty(itemId, "field").getValue().equals("0")) {
  16.                         System.out.println("qta_prel:"+myTable.getContainerProperty(itemId, "field").getValue());
  17.                     } else {
  18.                         cb.setValue(null);
  19.                         getWindow().showNotification("Type something", Window.Notification.TYPE_ERROR_MESSAGE);
  20.                     }
  21.                 }
  22.             }
  23.         });
  24.         return cb;
  25.     }
  26. });
  27. myTable.addContainerProperty("field", String.class, null);
  28.  
  29. // insert on table
  30. myTable.addItem(new Object[] { rs.getBoolean("chk1"), rs.getString("field") }, null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement