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.
JPAContainer, ComboBox and addNestedContainerPrope
Hi after read all posts about JPAContainer, FieldFactory and SingleSelectTranslator and lost days I found what didn't work on my code.
My Model is like (details are left outside):
public class Foo {
@NotNull
@Size(max = 255)
private String caption;
@ManyToOne(fetch = FetchType.EAGER)
private FooOwner fooOwner;
and
public class FooOwner {
@Id//pay attention to this, I think it is the problem
private String uniqueKey;
@NotNull
@Size(max = 255)
private String caption;
Then I have a vaadin table of Foo instances where I need to shows also Foo caption, and Foo uniqueKey, so on the Foo container I added a nestedProperty,
fooContainer.addNestedContainerProperty("fooOwner.caption");
fooContainer.addNestedContainerProperty("fooOwner.uniqueKey");
and the table columns are:
table.setVisibleColumns(new String[] { "id", "fooOwner.caption", "fooOwner.uniqueKey", "start", "end", "caption" });
On the Foo vaadin Form I pass the EntityItem<Foo>,
fooForm.setItemDataSource(fooItem, Arrays.asList(new String[] { "start", "end", "caption", "fooOwner" }));
I use the JPAContainer instance of FieldFactory and on the fooOwner I see a ComboBox (SingleSelectTranslator is used)
on update item all is ok, but if I create a new Item and save I got the following exception
java.lang.IllegalStateException: A null value was found in the chain of nested properties
If I remove the addNestedContainerProperty declaration and consequently the related table columns all works well.
Debugging the JPAContainerItem
public void commit() throws SourceException, InvalidValueException {
if (!isWriteThrough()) {
try {
/*
* Commit all properties. The commit() operation will check if
* the property is read only and ignore it if that is the case.
*/
for (ItemProperty prop : propertyMap.values()) {
prop.commit();
}
it gets the fooOwner properties and it seems to me as it confuse the fooOwner instence coming from comboBox with others fooOwner properties.
Could someone get me a rigth direction?
Does anyone did the same scenarious?
Regards
I found that adding a simple ValueChangeListener on the item like this,
this.item.addListener(new ValueChangeListener() {
@Override
public void valueChange(final ValueChangeEvent event) {
System.out.println(event);
}
});
all nested item properties are added to the Item propertyMap so when I commit the form
public void commit() throws SourceException, InvalidValueException {
if (!isWriteThrough()) {
try {
/*
* Commit all properties. The commit() operation will check if
* the property is read only and ignore it if that is the case.
*/
for (ItemProperty prop : propertyMap.values()) {
prop.commit();
}
modified = false;
container.containerItemModified(this);
} catch (Property.ConversionException e) {
throw new InvalidValueException(e.getMessage());
} catch (Property.ReadOnlyException e) {
throw new SourceException(this, e);
}
}
}
some properties (all unuseful nested properties) are null and
prop.commit();
will throws
Property.ConversionException
I don't know if this work as design or is a bug,
BTW I removed the listener, had the same functionality using a workaround.
Regards