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.
BeanValidationForm Object created but values always null in database ...
Hi there,
the BeanItem's values are always null but i don't know why ... ?? Is my implementation correct?
The entity is created but the values are null ....
package org.guitest.gui.dialogs.firms;
import com.vaadin.addon.beanvalidation.BeanValidationForm;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.FormFieldFactory;
import com.vaadin.ui.Select;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import java.util.Arrays;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import org.ba.thueringen.guitest.controller.FirmaSessionBean;
import org.ba.thueringen.guitest.gui.MainWindow;
import org.ba.thueringen.guitest.model.Firma;
import org.ba.thueringen.guitest.util.BeanLocator;
/**
*
* @author jakob
*/
public class FirmDetail extends VerticalLayout implements Button.ClickListener, FormFieldFactory {
private BeanItem<Firma> firmaItem = null;
private Form editor;
private Button save;
private Button cancel;
private MainWindow mainWindow;
FirmaSessionBean firmaSessionBean;
public FirmDetail(MainWindow mainWindow, Firma firma) {
this.mainWindow = mainWindow;
firmaSessionBean = (FirmaSessionBean) new BeanLocator.GlobalJNDIName().withModuleName("GUI-Test").withBeanName(FirmaSessionBean.class).locate();
//Create new Firm
if (firma == null) {
this.firmaItem = new BeanItem<Firma>(new Firma());
mainWindow.clearComponents("Firma anlegen", "Firmen - Firma anlegen", this);
} //Edit existing Firm
else {
this.firmaItem = new BeanItem<Firma>(firma);
mainWindow.clearComponents("Firma editieren", "Firmen - Firma editieren", this);
}
save = new Button("Speichern");
cancel = new Button("Abbrechen");
save.addListener(this);
cancel.addListener(this);
editor = new BeanValidationForm<Firma>(Firma.class);
editor.setFormFieldFactory(this);
editor.setWriteThrough(false);
editor.setImmediate(true);
editor.setItemDataSource(firmaItem, Arrays.asList("name1", "name2", "name3"));
editor.getFooter().addComponent(save);
editor.getFooter().addComponent(cancel);
addComponent(editor);
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void buttonClick(ClickEvent event) {
try {
if (event.getButton() == save) {
firmaSessionBean.addEntity(firmaItem.getBean());
editor.commit();
new FirmsList(mainWindow);
}
if (event.getButton() == cancel) {
editor.discard();
new FirmsList(mainWindow);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
// Identify the fields by their Property ID.
String pid = (String) propertyId;
if ("name1".equals(pid)) {
TextField textField = new TextField("Name1");
textField.setNullRepresentation("");
return textField;
}
if ("name2".equals(pid)) {
return new TextField("Name2");
}
if ("name3".equals(pid)) {
return new TextField("Name3");
}
if ("client".equals(pid)) {
Select select = new Select("City");
select.addItem("Berlin");
select.addItem("Helsinki");
select.addItem("London");
select.addItem("New York");
select.addItem("Turku");
select.setNewItemsAllowed(true);
return select;
}
return null;
}
}