Hi all,
Am facing a small issue with a beancontainer.
I have simple bean bound to a simple form with Fieldgroup.
final FieldGroup binder = new FieldGroup(sbItem);
binder.bindMemberFields(sf);
binder.setBuffered(true);
Now there is bean container that is populated when user adds a bean with the form.
The beancontainer is set as a souce to table.
final BeanContainer<String, SimpleBean> simpleBeanContainer =
new BeanContainer<String, SimpleBean>(SimpleBean.class);
…
final Table simpleTable = new Table(“Simple Table”, simpleBeanContainer);
simpleTable.setImmediate(true);
Now when I add a bean with the form for the first time, the bean is added to the table. When I add a different details with the form, the table gets added with the new bean for 2 times and the earlier row is removed.
For ex.
First time -
form data [abc,2]
click submit button
table data [abc,2]
Second time -
form data [def,4]
click submit button
table data -
[def,4]
[def,4]
Not sure why is [abc,2]
(first row) replaced.with [def,4]
.
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
final SimpleForm sf = new SimpleForm();
final SimpleBean sb = new SimpleBean();
BeanItem<SimpleBean> sbItem = new BeanItem<SimpleBean>(sb);
final BeanContainer<String, SimpleBean> simpleBeanContainer =
new BeanContainer<String, SimpleBean>(SimpleBean.class);
simpleBeanContainer.setBeanIdProperty("name");
final FieldGroup binder = new FieldGroup(sbItem);
binder.bindMemberFields(sf);
binder.setBuffered(true);
layout.addComponent(sf);
Button submitButton = new Button("Submit");
submitButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
binder.commit();
BeanItem<SimpleBean> simpleBeanItem = (BeanItem<SimpleBean>) binder.getItemDataSource();
simpleBeanContainer.addBean(simpleBeanItem.getBean());
} catch (CommitException e) {
e.printStackTrace();
}
}
});
Button discardButton = new Button("Discard");
discardButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
simpleBeanContainer.removeAllItems();
binder.discard();
}
});
HorizontalLayout buttonsHolder = new HorizontalLayout(submitButton, discardButton);
buttonsHolder.setSpacing(true);
buttonsHolder.setMargin(true);
layout.addComponent(buttonsHolder);
final Table simpleTable = new Table("Simple Table", simpleBeanContainer);
simpleTable.setImmediate(true);
simpleTable.setSelectable(true);
simpleTable.setHeight("300px");
simpleTable.setVisibleColumns("name","number","telephoneNumbers","certificationsDone");
layout.addComponent(simpleTable);
}
Larsen,