我有BeanItemContainer,這是我通過JDBC從數據庫中加載:如何綁定BeanItemContainer到組合框
BeanItemContainer myBeans = new BeanItemContainer<>(MyBean.class, mybeanDao.findAll());
,這是我如何安裝到組合框:
Combobox combo = new Combobox();
combobox.setContainerDataSource(myBeans);
到目前爲止,一切都很好。我收到了我想要的,但現在我有一個問題 - 如何獲得已選擇的實際ID?這必須是同步的(在combobox中選擇的id是數據庫中的實際條目)。
我不知道,該如何解決這個問題
請幫
PS爲myBean類
public class MyBean {
private Long id;
private String field1;
*** getters /setters ***
and toString() {} method
}
我測試了你的選擇,它運行良好。但是有一個問題。你看我有vaadin spring應用程序,並且這個假設將這個beanItemContainer附加到模態窗口。所以我需要在用戶導航到模態窗口時從數據庫預加載bean。我試圖使用@PostConstruct,但它什麼也沒做(或者我弄錯了)。非常感謝 – Reborn
我的方法沒有看到任何問題。它應該工作。大概你可以分享一些代碼。 –
不幸的是,我不能讓代碼atm,但是當它完成時我會告訴你。敬請期待。 – Reborn