is there any example which explains how to use combobox, in order to set foreign key field value?
For example, imagine typical Department/Employees relationship, where on the Employee entity exists
deptId field (BigDecimal), representing foreign key to the Department. Now, in order to show Department choices,on the Employee form, I am using Combobox filled with BeanItemContainer built on Department entitties. But, how to ensure that Employee’s.deptId field are filled with appropriate Department.Id, when user choose something from the combobox?
Should I use Converter for the Combobox, and if so, how?
Do you have a proper relation in your JPA model or manually working with identifieers? The combobox’s value should be the same as the edited type, then no converters are needed.
It don’t actually have an example of ManyToOne relation, but there is ManyToMany. The principle is the same in both, just that in ManyToOne you can use ComboBox. I actually suggest to use TypedSelect from Viritin instead of combobox, that contains bettter typed API (and no need to wrap your options into BeanItemContainer) that make things much more easier to understand.
Multiple writable mappings exist for the field [Employee.DEPT_ID]
. Only one may be defined as writable, all others must be specified read-only.
So, if I understand you correctly, what you suggest, is to use cobombox for the @ManyToOne master_dept field, but I cannot do that. I ended up with Converter between Object (holding by Combobox) and BigDecimal (deptId)
Do you have any other suggestion?