我有3个组合框。其中两个工作得很好,但我的第三个不是向我的听众发送更改事件,但是,如果我选择空行(null select),那么我得到了事件。以前有人有这个问题吗?在我的下面的代码中,无效的是companyCombobox,而work是personCombobox
有关代码的更多信息
关于代码,组合框依赖于彼此的选择,如果在combo1中选择了一个值,则将一些给定的实体加载到combo2和combo3中。如果您从选择combo2开始,那么combo1和combo3应该更新数据源。 每次发生更改事件时都会调用setPersonCompanyComboDataSource()。我不包括这部分代码。
private void initComboBoxes() {
personCombo = getComboBox("orderwiz.orderheadstep.contactwiz.personComboBoxTitle", "orderwiz.orderheadstep.contactwiz.personComboBox");
companyCombo = getComboBox("orderwiz.orderheadstep.contactwiz.companyComboBoxTitle", "orderwiz.orderheadstep.contactwiz.companyComboBox");
contactInfoCombo = getComboBox("orderwiz.orderheadstep.contactwiz.contactInfoComboBoxTitle", "orderwiz.orderheadstep.contactwiz.contactInfoComboBox");
initRolesCombo();
setPersonCompanyComboDataSource();
}
protected ComboBox getComboBox(String title, String inputPrompt)
{
ComboBox dropDown = new ComboBox(DT.get(title));
dropDown.setFilteringMode(Filtering.FILTERINGMODE_OFF);
dropDown.setMultiSelect(false);
dropDown.setNullSelectionAllowed(true);
dropDown.setInvalidAllowed(false);
dropDown.setNewItemsAllowed(true);
dropDown.setInputPrompt(DT.get(inputPrompt));
dropDown.setItemCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
dropDown.setItemCaptionPropertyId("myItemCaption");
dropDown.setImmediate(true);
dropDown.setWidth("100%");
return dropDown;
}
private void setPersonCompanyComboDataSource() {
if(myModel.getSelectedContactType() == TYPES.PERSON){
setSelectedPersonComboDataSource();
}else if(myModel.getSelectedContactType() == TYPES.COMPANY){
setSelectedCompanyComboDataSource();
}else{
//we reset the comboboxes if there has been a reset or no value is selected in the search
personCombo.setContainerDataSource(null);
companyCombo.setContainerDataSource(null);
}
}
/**
* Set the person combobox to hold the selected person and fills all related companies in the companyCombobox
*/
private void setSelectedPersonComboDataSource(){
BeanItemContainer<PersonWrapper> personContainer = new BeanItemContainer<PersonWrapper>(PersonWrapper.class);
personContainer.addItem(new PersonWrapper(myModel.getSelectedPerson()));
personCombo.setContainerDataSource(personContainer);
personCombo.setValue(personContainer.firstItemId());
companyCombo.setContainerDataSource(new BeanItemContainer<CompanyWrapper>(CompanyWrapper.class));
for(Company c : myModel.getCompaniesFromPerson(myModel.getSelectedPerson())){
companyCombo.addItem(new CompanyWrapper(c));
}
if(myModel.getCompaniesFromPerson(myModel.getSelectedPerson()) != null && myModel.getCompaniesFromPerson(myModel.getSelectedPerson()).size() == 1){
companyCombo.setValue(companyCombo.getItemIds().iterator().next());
}
}
/**
* Set the selected company to companyBox and fills all related persons to the personsCombobox
*/
private void setSelectedCompanyComboDataSource(){
BeanItemContainer<CompanyWrapper> companyContainer = new BeanItemContainer<CompanyWrapper>(CompanyWrapper.class);
companyContainer.addItem(new CompanyWrapper(myModel.getSelectedCompany()));
companyCombo.setContainerDataSource(companyContainer);
companyCombo.setValue(companyContainer.firstItemId());
personCombo.setContainerDataSource(new BeanItemContainer<Person>(Person.class));
for(Person p : myModel.getPersonsFromCompany(myModel.getSelectedCompany())){
personCombo.addItem(new PersonWrapper(p));
}
if(myModel.getPersonsFromCompany(myModel.getSelectedCompany()) != null && myModel.getPersonsFromCompany(myModel.getSelectedCompany()).size() == 1){
personCombo.setValue(personCombo.getItemIds().iterator().next());
}
}
答案 0 :(得分:3)
所以我发现了问题所在。我的实体提供了一种等于方法,使所有选择看起来都相同。
在我的实体中,我有一个equals方法,在正常情况下可以正常工作,但是,我的数据库包含很多测试数据,复制的公司具有完全相同的数据,除了他们的ID,并且ID不包含在因业务规则而非等于方法(不是我的规则)。因此,当组合框加载我的所有公司并且我做了一个选择时一切正常但当我做另一个选择并且新选择的实体匹配旧实体时因为equals方法vaadin没有触发更改事件,因为它是同一个对象根据我的平等规则。
答案 1 :(得分:0)
在我的情况下,我在自定义容器中实现了错误的getItemIds()和containsId()。 containsId()是生成的&#39;返回false&#39;。这也会阻止选择监听器工作。