Nullable Nested Columns

I try to obtain any anwer of this big problem.

Exist any way to add nested columns nullable in a beanitemContainer?, Whitch container i must use to add a list of beans when exist nested columns that could be nullable?? I do not want use generate columns to resolve this problem!!

Regards

I’m not sure what you mean with nullable columns, but if I guess correctly, my add-on
MCont
might help.

The problem is related with this categorical phrase in vaadin book (version 6, 9.4.1 chapter: BeanContainer about Nested-Columns):

‘As with a top-level bean in a bean container, also a nested bean must have public visibility or otherwise an access exception is thrown. Intermediary getters returning a nested bean must always return a non-null value.’

My model have many situations where with have null values in some nested propesties like this example: stock.expedition.client.name
Where Expedition is a bean with an attribute Client, and sometimes the Stock bean don’t have any Expedition asociated, so if I used Nested-Columns to show the client name I obtain errors when some Stock bean dont’ have any Expedition.

So my question is: How can inject a data source in my vaadin table when some nested properties are sometimes null??

regards.

This actually changed a while ago in Vaadin 7.x (cannot recall the exact version). Now nested properties in BeanContainer/BeanItemContainer support intermediate null values and just return null when reading the property value.

It’s sound perfect, but our problem is that our app (konekti, 3 years old) is a very very big with a lot of code is in Vaadin6 so is imposible for us migrate. So this question is for Vaadin6, exist any possibility to sorround this problem??, we are using BeanItemContainer to manage aour data in all the app.

Is not possible that Vaadin resolve this problem in Vaadin 6, for the people like us, that we are using this version will be very important!.

anyway, we are thinking in 3 ways to address the problem:

  1. Use the IndexedContainer (not so assisted like BeanItemContainer) and resolve this situation.
  2. Extend the BeanItemContainer and resolve this situation.
  3. Patch the NestedMethodProperty (I think that this class is where exist this problem) of any vaadin version, recompile it and use it.

This is the code of the NestedMethodProperty where we think is the problem:
/**
* Gets the value stored in the Property. The value is resolved by calling
* the specified getter method with the argument specified at instantiation.
*
* @return the value of the Property
*/
public Object getValue() {
try {
Object object = instance;
for (Method m : getMethods) {
object = m.invoke(object);
}
return object;
} catch (final Throwable e) {
throw new MethodException(this, e);
}
}

What is your opinion ??.

Regards.

Yes, 3) is the easiest way to go. It should be enough to copy the source code of this class to your project and edit the getValue() method so that on each iteration of the loop, the method returns null if the intermediate value is null.

The other alternative would normally be to subclass the relevant classes (AbstractBeanContainer.addNestedContainerProperty(), NestedPropertyDescriptor, NestedMethodProperty) to reduce the amount of code to copy, but in that case you also need to keep a separate copy of the private “instance” in NestedMethodProperty as the field is private.

Thanks Henri,

I choosed the third option that you told me, we take the last sources of vaadin 6.8 (6.8.15) and modify the getValue of the NestedMethodProperty class and works OK. But I have a little question.

My patched in Vaadin6 sources is:

public Object getValue() {
try {
Object object = instance;
for (Method m : getMethods) {
if (object != null)
object = m.invoke(object);
}
return object;
} catch (final Throwable e) {
throw new MethodException(this, e);
}
}

And the sources of the last vaadin 7 (7.2.6) version is:
@Override
public T getValue() {
try {
Object object = instance;
for (Method m : getMethods) {
object = m.invoke(object);
if (object == null) {
return null;
}
}
return (T) object;
} catch (final Throwable e) {
throw new MethodException(this, e);
}
}

The question is that the source code of the vaadin 7 is not that wrong??, because it check if object is null after execute the reflection code of m.invoke(object) so I suspect that this code faild again with null nested columns.

What is your opinion??

Regards

The Vaadin 7 version assumes that instance (top level bean) is not null, which should always be the case as long as not allowing null beans in the container. Any level below that can be null.