ComboBox in forms and databinding

Hi All,

I have a simple one-to-many relation between to classes (Server and Type). I try to present the types as a ComboBox in the Server creation From. My objects are persisted using the hbnContainer.

Everything works fine, until I try to “apply” the changes using a form.commit(). The problem is that the ComboBox returns the ID (as Long) of the chosen Type, however the code can’t convert the ID to the actual Type.

I can see that it tries to call the constructor of my Type class with the ID as parameter. But that is not right. The container should be called to create type object using the ID. I would prefer not to clutter my Pojo.

Please help how should I do it right ?

Here is how I have sett up the Form :

And here is the code for creating the ComboBox in myFieldFactory.

Hi!

HbnContainer uses primary keys as identifiers. It also uses them as Item values in case of a relation. If you would be using an Item provided by HbnContainer in the Form too, things would be working just fine here.

I can’t guess which is easier for you to change, but either use items provided by HbnContainer in Form too or list combobox options into a container that uses objects a identifiers like BeanItemContainer.

cheers,
matti

Thanks allot for your help.

So to summarize it all. What I did wrong was that I used the Server as a Pojo instead of EntityItem taken from HbnContainer.

All I needed to do was removing line 3 and 4 and to use entityItem directly as the datasource. Easy when you know it is possible :slight_smile:

Regards,
Armaz