BeanFieldWrapper and ComboBox

Hi guys, I’m using BeanFieldWrapper to wrap a list of Entities to a ComboBox inside a form that use BeanItem as a datasource.

I’m facing a rare case, maybe I’m not understand very well how it’s supposed to work. this is the case:

  1. First I set my form datasource to a instance Object lets say MyObject this objects has a method getOtherObject mapped to a ComboBox, the combo contain a list of OtherObject readed from a Database, this steps work very well and the comboBox shows the selected item correctly.

  2. Then I make no changes to the form fields and I commit it, when commited the MyObject instance set the OtherObject instance to null using the method setOtherMethod

I have traced the error and found that it’s falling in the following code when no changes are made to the comboBox Selection it returns the value from the datasource, the value returned is the mapped id of the OtherObject and not the instance to be set in MyObject instance.

Hope you can understand my explanation… I’m not good at english :frowning:

This is the code used inside DEfaultFormFactory

ComboBox cronJobComboBox = new ComboBox();
cronJobComboBox.setNullSelectionAllowed(false);
cronJobComboBox.setImmediate(true);
cronJobComboBox.setRequired(true);
cronJobComboBox
.setRequiredError(“Debe seleccionar una tarea”);
BeanItemContainer container = new BeanItemContainer(
CronJob.class);
List cronJobs = cronJobService.listCronJobs();

				for (CronJob cronJob : cronJobs) {
					container.addBean(cronJob);
				}

				cronJobComboBox.setContainerDataSource(container);

				f = new BeanFieldWrapper<CronJob>(cronJobComboBox,
						CronJob.class, container, "id");
				f.setCaption("Tarea");

and this is how I set the datasource of the form

private void setFormDataSource(CronJobTrigger trigger) {
cronJobTrigger = trigger;
BeanItem cronJobTriggerBeanItem = new BeanItem(
cronJobTrigger);
cronJobTriggerForm.setItemDataSource(
cronJobTriggerBeanItem,
Arrays.asList(new String { “id”, “name”, “description”,
“cronJob” /* THE COMBOBOX */, “expression” }));
}

this is the code that return the id value when the combobox is no modified:

AbstractField.java

public Object getValue() {

    // Give the value from abstract buffers if the field if possible
    if (dataSource == null || !isReadThrough() || isModified()) {
        return value;
    }

    Object newValue = String.class == getType() ? dataSource.toString()
            : dataSource.getValue();

    return newValue;
}

Thank you guys!!!
11827.java (14.2 KB)
11828.java (3.76 KB)
11829.java (5.58 KB)