Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Table as customField in form => How to implement write through false
I have a form. One of the fields of that Form is a CustomField with inside a Table which is bound to a BeanItemContainer.
Allthough I put prsTable.setWriteThrough(false) when I enter something in one of the texfields then the changes are immediately submitted to the beans. I just want that to happen when I press confirm of the form
This is my customField class. How can I solve this?
public abstract class PrsTableCustomField<BEANTYPE extends Entity<Long>, BEANITEMCONTAINER extends PrsTableBeanItemContainer<BEANTYPE>, FIELDMAP extends FieldMap>
extends CustomField implements Initializable {
private static final Logger LOGGER = Logger.getLogger(PrsTableCustomField.class);
BEANITEMCONTAINER beanItemContainer;
@Inject
PrsTable prsTable;
@Inject
MessageSource translate;
VerticalLayout layout = new VerticalLayout();
public PrsTableCustomField() {
setCompositionRoot(layout);
}
@Override
public void setWriteThrough(boolean writeThrough) throws Buffered.SourceException, InvalidValueException{
prsTable.setWriteThrough(false);
}
@Override
public Class<?> getType() {
return Set.class;
}
@Override
public void attach() {
super.attach();
}
@Override
public void setPropertyDataSource(Property newDataSource) {
Object value = newDataSource.getValue();
if (value instanceof Set<?>) {
@SuppressWarnings("unchecked")
Set<BEANTYPE> beans = (Set<BEANTYPE>) value;
beanItemContainer.removeAllItems();
beanItemContainer.addAll(beans);
prsTable.setPageLength(beans.size());
} else {
throw new IllegalArgumentException("property needs to be a Set");
}
super.setPropertyDataSource(newDataSource);
}
@Override
public Object getValue() {
Set<BEANTYPE> beans = new HashSet<BEANTYPE>();
for (Object itemId : beanItemContainer.getItemIds()) {
beans.add(beanItemContainer.getItem(itemId).getBean());
}
return beans;
}
@Override
public void setReadOnly(boolean readOnly) {
prsTable.setEditable(!readOnly);
super.setReadOnly(readOnly);
}
public void initialize() {
String captionKey = getCaptionKey();
if (captionKey != null) {
setCaption(translate.message(captionKey));
}
beanItemContainer = getBeanItemContainer();
prsTable.setContainerDataSource(beanItemContainer);
prsTable.setTableFieldFactory(getFieldMapTableFieldFactory());
prsTable.setEditable(!isReadOnly());
prsTable.setWriteThrough(false);
layout.setSizeFull();
layout.setSpacing(true);
prsTable.setSizeFull();
setSizeFull();
layout.addComponent(prsTable);
}
public abstract BEANITEMCONTAINER getBeanItemContainer();
public abstract String getCaptionKey();
public abstract FIELDMAP getFieldMap();
protected FieldMapTableFieldFactory<FIELDMAP> getFieldMapTableFieldFactory(){
FIELDMAP fieldMap = getFieldMap();
return new FieldMapTableFieldFactory<FIELDMAP>(fieldMap);
}
@SuppressWarnings("serial")
private static final class FieldMapTableFieldFactory<FIELDMAP extends FieldMap> implements TableFieldFactory {
private final FIELDMAP fieldMap;
public FieldMapTableFieldFactory(FIELDMAP fieldMap) {
this.fieldMap = fieldMap;
}
public Field createField(Container container, Object itemId, Object propertyId,
Component uiContext) {
Field field = null;
FieldBuilder fieldBuilder = fieldMap.get(propertyId);
if (fieldBuilder != null) {
field = fieldBuilder.build();
field.setCaption("");
((AbstractComponent) field).setImmediate(true);
((AbstractComponent) field).setData(itemId);
}
return field;
}
}
public MessageSource getTranslate() {
return translate;
}
}