SetValue on a Select with objects as values


I have been using Vaadin for a few weeks now and it looks/feels great. I have encountered a small problem that I cannot figure out though. It may be simple but I could not find a solution in the documentation.

I have a Select object that I fill with Hibernate pojos. Then, to set the default value, I call setValue() but nothing happens, not even an exception. The object used to call setValue() is not the same as the one in the select but I have overridden equals() so I guessed it would be ok. I also tried to set the value with the text displayed in the select but nothing happens either (to set the text I have my own toString() method).

A small example :

class Pojo
    getters and setters


Pojo myValue;
Select s = new Select();
for (Pojo p : listOfPojos)
    s.addItem(p);; // Nothing happens

Hope someone can help!



Hi François,

I think that you have an error on your example

You have to assign a valid value to your Pojo class and then call select.

Pojo myValue = new Pojo(); // this pojo should be in listOfPojos

Select s = new Select();
for (Pojo p : listOfPojos)
    s.addItem(p);; // Should work

Anyway if you call to setValue with the pojo should work.


You could also put the pojos in a BeanItemContainer or HbnContainer and then bind the Select to that. Defining toString() to have a caption for the pojos works as well, as you have done, but it’s a bit nicer to use setCaptionProperty() for that. Well, whatever works best for you.