Hello,
Please, i have been dealing with this for days, i dont know what im doing wrong. I was requested to change some of my aplicacion forms to in-line table editing to speeds things up, but i cant figure out how to do this. I need a checkbox to update a value in the same row (quite simple) my code seems to get somehow in a loop. I`ve tried diferent aproches like:
table.getContainerProperty(itemId, "value")
.setValue(BigDecimal.ZERO);
Or
table.refreshRowCache();
The code below: (Vaadin 6.8.13)
@SuppressWarnings("serial")
public class MyBean implements Serializable {
private Long id;
private boolean check;
private BigDecimal value;
public MyBean() {
}
public MyBean(Long id, boolean check, BigDecimal value) {
super();
this.id = id;
this.check = check;
this.value = value;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public boolean isCheck() {
return check;
}
public void setCheck(boolean check) {
this.check = check;
}
public BigDecimal getValue() {
return value;
}
public void setValue(BigDecimal value) {
this.value = value;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof MyBean)) {
return false;
}
if (this.id == null) {
return super.equals(object);
}
MyBean other = (MyBean) object;
if ((this.id == null && other.id != null)
|| (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
}
import java.math.BigDecimal;
import com.vaadin.data.Container;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.Table;
import com.vaadin.ui.TableFieldFactory;
import com.vaadin.ui.Window;
@SuppressWarnings("serial")
public class ContratoFormNew extends Window {
public ContratoFormNew() {
BeanItemContainer<MyBean> beanItemContainer = new BeanItemContainer<MyBean>(
MyBean.class);
beanItemContainer.addBean(new MyBean(1l, true, BigDecimal.TEN));
final Table table = new Table("", beanItemContainer);
table.setSizeFull();
table.setTableFieldFactory(new TableFieldFactory() {
@Override
public Field createField(Container container, final Object itemId,
Object propertyId, Component uiContext) {
if ("check".equals(propertyId)) {
System.out.println("CHECK BOX");
CheckBox check = new CheckBox();
check.setImmediate(true);
check.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
System.out.println("VALUE CHANGE: "
+ event.getProperty().getValue());
table.getContainerProperty(itemId, "value")
.setValue(BigDecimal.ZERO);
table.refreshRowCache();
}
});
return check;
}
return null;
}
});
table.setVisibleColumns(new String { "id", "check", "value" });
table.setEditable(true);
addComponent(table);
setWidth("400px");
setHeight("400px");
center();
}
}
I`ve been working with vaadin for 3 years now but i cant figure this out!! Any help will be very appreciated.