我有一个Vaadin表,我想动态添加行。
我试过的代码工作正常,当我点击添加行按钮时,表格中会出现一个新行。问题是,当我点击第二个,第三个等时间的按钮时,表中没有出现新行。我想在单击按钮时添加任意数量的行。我怎么能指甲呢?
以下是创建表格的代码:
public Table createTable(BeanContainer beans) {
table.setContainerDataSource(beans);
table.setColumnHeader("PS_SECTION", "ID");
table.setColumnHeader("NAME", "SECTION");
table.setColumnHeader("VORDER","ORDER");
table.addGeneratedColumn("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("");
Set<Object> keys = itemIdToCheckbox.keySet();
for (Object key : keys) {
PS_SECTION PS = (PS_SECTION) sectionMap.get(key);
if (PS.getISACTIVE() == 1) {
CheckIt(key,true);
}
else if(PS.getISACTIVE() == 0){
CheckIt(key,false);
}
}
checkBox.addAttachListener(new AttachListener() {
@Override
public void attach(AttachEvent event) {
itemIdToCheckbox.put(itemId, checkBox);
tableToCheck.put(itemId, checkBox);
}
});
checkBox.addDetachListener(new DetachListener() {
@Override
public void detach(DetachEvent event) {
itemIdToCheckbox.remove(itemId);
tableToCheck.remove(itemId);
}
});
checkBox.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(Property.ValueChangeEvent event) {
Boolean selected = (Boolean) event.getProperty().getValue();
}
});
return checkBox;
}
});
table.setMultiSelect(false);
table.setVisibleColumns(new Object[]{"PS_SECTION", "NAME", "VORDER", "ACTIVE"});
table.setEditable(true);
table.setSelectable(true);
table.setImmediate(true);
table.commit();
return table;
}
这是容器代码:
public BeanContainer createContainer() {
beans.setBeanIdProperty("PS_SECTION");
for (int i = 0; i < list.size(); i++) {
PS_SECTION section = list.get(i);
Long ps = section.getPS_SECTION();
String na = section.getNAME();
Long is = section.getISACTIVE();
Long isg = section.getISGLOBAL();
Long or = section.getVORDER();
Integer st = section.getSTATUS();
beanlist.add(new PS_SECTION(ps, na, is, isg, or, st));
}
beans.addAll(beanlist);
return beans;
}
最后,行添加按钮代码:
addButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Object newbean = beans.addBean(new PS_SECTION(0L, null, 0L, 0L, 0L, 0));
table.addItem(newbean);
}
});
还尝试以下方法以避免重复。同样的事情发生了
long in = 200;
Object newbean = beans.addBean(new PS_SECTION(in, null, 0L, 0L, 0L, 0));
++in;
table.addItem(newbean);
答案 0 :(得分:1)
保持这一行:
> db.geo.find()
{
"_id": ObjectId("586e663175c32828be59e3a9"),
"zoneCoordinates": {
"type": "Polygon",
"coordinates": [
[
[2, 0],
[6, 0],
[6, 2],
[2, 2],
[2, 0]
]
]
}
}
> db.geo.find({
"zoneCoordinates": {
"$geoIntersects": {
"$geometry": {
"type": "Point",
"coordinates": [3 ,1]
}
}
}
}).count()
1
在添加按钮clicklistener代码之外。也许你可以成为全球(类)成员;