我有一个可编辑的Vaadin表,其中有一个复选框列。
当项目的条件为getISACTIVE = 1
(长数据,取自数据库)时,我希望选中复选框。
另一方面,当我更改复选框的值时,我希望相应地更改ISACTIVE
条件(正在检查setISACTIVE=1
并且未检查setISACTIVE=0
。
到目前为止,我尝试映射复选框,但即使条件= 1,仍然不会检查复选框。
知道我该怎么办?
table.addGeneratedColumn("Is Active", new Table.ColumnGenerator() {
private static final long serialVersionUID = 1L;
@Override
public Object generateCell(final Table source, final Object itemId,
Object columnId) {
final CheckBox checkBox = new CheckBox("");
//ITERATE THROUGH DATABASE, THEN getPS_SECTION that is the ID Bean Property
for (int i = 0; i < list.size(); i++) {
PS_SECTION section = list.get(i);
Long sc = section.getPS_SECTION();
FillIt(sc,checkBox);
if (section.getISACTIVE() == 1L) {
value = true;
CheckIt(sc,value);
}
else if(section.getISACTIVE() == 0L){
value = false;
CheckIt(sc,value);
}
}
checkBox.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Boolean isTrue = checkBox.getValue();
if (isTrue){
isChecked = true;
Notification.show("Is activated" );
//setISACTIVE = 1
}
else{
isChecked = false;
Notification.show("Is deactivated" );
//setISACTIVE = 0
}
}
});
return checkBox;
}
});
table.setTableFieldFactory(new DefaultFieldFactory() {
public Field<?> createField(Container container, final Object itemId, Object propertyId, Component uiContext) {
if (CHECKBOX_COLUMN.equals(propertyId)) {
CheckBox field1 = new CheckBox();
field1.setImmediate(true);
}
return super.createField(container, itemId, propertyId, uiContext);
}
});
这里有方法FillIt()
和CheckIt()
:
private void CheckIt(Long id, Boolean value) {
CheckBox checkBox = itemIdToCheckbox.get(id);
checkBox.setValue(value);
}
private void FillIt(Long id, CheckBox checkBox) {
itemIdToCheckbox.put(id,checkBox );
}
//When itemIdToCheckBox is
protected Map<Long, CheckBox> itemIdToCheckbox = new LinkedHashMap<Long, CheckBox>();
答案 0 :(得分:0)
private void CheckIt(Long id, Boolean value) {
CheckBox checkBox = itemIdToCheckbox.get(id);
checkBox.setValue(value);
}
这是什么&#34; itemIdToCheckbox.get(id)&#34;办?