Adding beanItem from Form's datasource to Table's datasource?


I have no idea is this stupid question or not, but for me, it’s important :slight_smile:

I have a page divided to two horizontal panels. In left side I’ve got table called staffTable. In right side I’ve got a form, called addingUserForm. I am trying to add users/staff to the table using that form.

Table’s data source is BeanItemContainer:

 final BeanItemContainer<Staff> container = new BeanItemContainer<Staff>(Staff.class);
staffTable = new Table("Adding staff", container);
staffTable.setVisibleColumns(new String[] {"firstName","lastName", "userName"});
staffTable.setColumnHeader("firstName", "First Name");
staffTable.setColumnHeader("lastName", "Last Name");

Form’s datasource is BeanItem

staffItem = new BeanItem<Staff>(staff);
staffItem.addItemProperty("company", new NestedMethodProperty(staff, "company.companyName"));
addingUserForm = new Form();

When I press the button my bean is populated, so staffItem gets the data:

Button apply = new Button("Add", new Button.ClickListener() {
	public void buttonClick(ClickEvent event) {
                try {
                        // Adds a new staff to table's dataSourceContainer

And the question is:

When I am adding new staff I am always using a same instance of staffItem, so I can’t add a new one at all, I just change the old object. Size of the container is always 1. Is there some kind of convenient way to do that?

container.addItem(new BeanItem((Staff)staffItem.getBean()));----> This is NOT working
container.addBean(new Staff(copying everything from BeanItem to staff)) // new constructor, sounds bad


Hi Sami,

Try with this:


It should work.

Hope this helps.


Hi and thanks!

It does exactly the same because in my case there is the same staffItem-instance, so it change the the same object and not make the new one.

Image after adding first item to container

Img2 after second bean added to container

Maybe I have to design the whole code again, because I can’t fix that, I just need NEW object/beanitem from the staffitem :frowning:


I have a layout what includes splitPanel (Table + Form). I recognized as well that t.setSelectedTab(tabLayout4);
t.requestRepaintAll(); is NOT working. When the user press the “everything done” in that page, user is not transferred to the next tabsheet called tabLayout4. It’s working in everywhere else but not in that case, have you idea for that? The “everything done”-button is in layout what is inside of the panel.

Links to pictures:

Thanks a lot for helping me, I really appreciate it!


This is what i suggest to resolve your problem :

If you change your listener a little bit, I think it would do it.

Button apply = new Button("Add", new Button.ClickListener() {
    public void buttonClick(ClickEvent event) {
                try {

                     // Rebind your form with a new instance of BeanItem
                     staffItem = new BeanItem<Staff>(new Staff()); 



JIHUUUUUU! That was it :slight_smile: Thanks thanks thanks! Have you an idea to my second question.

I implemented a new form-class called StaffForm, because my file started to be horrible and too big etc. I used your logic and that was it, I am so happy now :slight_smile:
BTW, how big work is to change the container type to SQLContainer? Finally I have to do it. I have a 5 tabsheets and I am creating a new company with staff, branches, basic infos etc. Now I am just collecting data to CompanyBean and after the last tab everything is going to the database when user press save-button. Is that wise idea or should I add everything pieve by piece to the DB?

			staffItem = new BeanItem<Staff>(new Staff()); 
			staffItem = addPropertiesToStaffItem(staffItem); //add nested properties to staffItem


I never use SQL Container, so I can’t tell.

For your question #2 : I’m not sure I understand perfectly. But if you want the user to be redirected to a specific tab, you can do something like this :

 // Tabsheet is a reference to the tabsheet where your layout in attach
 tabSheet.setSelectedTab(//here you insert the index of the tab you want to select)

Not tested it, but I think it would work.