(抱歉,如果這是一個有點福利局問題的)Vaadin 7.0.1組合框與JPAContainer和FIELDGROUP
我有兩個JPAContainers,一個用於一個Employee類/表,一個用於語言類/表。員工可以擁有選定的語言。
我想創建一個員工編輯窗體與語言選擇和FieldGroup組合框來處理綁定和創建。
我可以通過JPAContainer從語言表中包含條目,但它不會在員工記錄中顯示已經存在的值。我究竟做錯了什麼?
//Key parts of code....
private JPAContainer<Employee> employees;
private JPAContainer<Language> languages;
FormLayout formLayout = new FormLayout();
formFieldGroup = new FieldGroup(employeeItem);
Field<?> firstName = formFieldGroup.buildAndBind("First name", "firstName");
Field<?> lastName = formFieldGroup.buildAndBind("Last name", "lastName");
Field<?> userName = formFieldGroup.buildAndBind("Username", "userName");
Field<?> fullName = formFieldGroup.buildAndBind("Full name", "fullName");
Field<?> initials = formFieldGroup.buildAndBind("Initials", "initials");
ComboBox language = new ComboBox("Language",languages);
language.setContainerDataSource(languages);
language.setItemCaptionPropertyId("languageName");
language.setFilteringMode(FilteringMode.CONTAINS);
language.setImmediate(true);
formFieldGroup.bind(language, "language");
firstName.addValidator(new BeanValidator(Employee.class, "firstName"));
lastName.addValidator(new BeanValidator(Employee.class, "lastName"));
firstName.addValidator(new BeanValidator(Employee.class, "userName"));
lastName.addValidator(new BeanValidator(Employee.class, "fullName"));
lastName.addValidator(new BeanValidator(Employee.class, "initials"));
formLayout.addComponent(userName);
formLayout.addComponent(fullName);
formLayout.addComponent(firstName);
formLayout.addComponent(lastName);
formLayout.addComponent(initials);
formLayout.addComponent(language);
// A few details of the domain classes
@Entity
@Table(name="Employees")
public class Employee extends BaseEntity
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="EmployeeID")
private Integer employeeID;
...
@ManyToOne
@JoinColumn(name="LanguageID",updatable=false)
private Language language;
...}
@Entity
@Table(name="Languages")
public class Language extends BaseEntity
{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="LanguageID")
private Integer languageID;
@Column(name="LangaugeName")
private String languageName;
... }
你是說你希望它默認爲僱員的語言作爲選定的語言,或者你的意思是如果你的數據庫中有法語,德語和英語,而員工Bob有德語,你的組合框只顯示法語和英語? – CorayThan 2013-03-08 06:46:05
它應該調出Employee記錄中已經設置的語言(在系統初始化時已經創建並且已經檢查過,以確定它具有正確的ID)。看來,FieldGroup沒有正確綁定到組合框,但我不能說我做錯了什麼/缺少。 – Michael 2013-03-08 09:26:00