CheckBox in Table with DefaultFieldFactory

Hi,
I use the same DefaultFieldFactory for a form and a table. My bean has a boolean property and in the createField, for this boolean property, I create the field in this way:

f = super.createField(item, propertyId, uiContext);
((AbstractField)f).setImmediate(true);

The form display the property correctly as a CheckBox, but the table (in non editable mode) display a text column whith value true/false. When I select a table row, I get:

Caused by: java.lang.IllegalArgumentException: CheckBox only accepts Boolean values
	at com.vaadin.ui.Button.setInternalValue(Button.java:348)
	at com.vaadin.ui.AbstractField.discard(AbstractField.java:300)
	at com.vaadin.ui.AbstractField.setPropertyDataSource(AbstractField.java:556)
	at com.vaadin.incubator.spring.ui.LookupForm.rebind(LookupForm.java:112)
	at com.vaadin.incubator.spring.ui.LookupForm.update(LookupForm.java:96)
	at com.vaadin.incubator.spring.ui.funzioni.Lookup.itemClicked(Lookup.java:345)
	at com.vaadin.incubator.spring.ui.LookupTable.itemClick(LookupTable.java:104)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
	... 63 more

How can I display a CheckBox inside the table ?

Thank you, Francesco

Not sure what your problem is, you must have mixed some types somewhere.

The examples below show two cases. The editable mode is the normal case for having components in a table, but you can put them in a table in non-editable mode as well.

[list]

[]

in non-editable mode

[
]

in editable mode

[/list]In these examples, the items are added to the table as object arrays, not from a BeanItem, but that should work just as well.

Marko,
your links are not available…
Thank you, Francesco

We moved on monday and the tomcat apparently did not restart automatically. It seems to work again.

Hi

I just fixed the same Exception from our application. It was caused by a Boolean object which didn’t have a value yet. A null Boolean doesn’t default to false in Vaadin checkbox, which we would have hoped, but gave the Exception.

So make sure the object you pass to your field factory has a value. We forced default values to our database to facilitate this.

Valtteri,
thank you for your suggestion. I fixed my problem initializing boolean properties to false on creation.
Thank you again, Francesco