RE: Adding item to table

Hi,

Actually it seems you’re running in to a fairly common gotcha: addItem() does not accept an Item but an Object that is to be the new item’s id.
I.e. you can not ‘force-feed’ Items to the IndexedContainer, it want’s to create it’s own Items.
This:

getHostList().getContainerDataSource().addItem( getHostForm().getItemDataSource() );

should be something like:

Object id = getHostList().getContainerDataSource().addItem(); // this will generate an id, you can also give one
Item newItem = getHostList().getContainerDataSource().getItem(id);
// [...]
 fill the item

In your example, this would require copying the stuff from the HostForm item to the HostList item, which is a bit odd, with this information you might want to rewrite a litte. Also, creating a new Container just to get a new Item is never a good idea (as in HostForm).

One solution would be to create a separate bean (POJO) for your actual data, and use BeanItem and BeanItemContainer to bind it to the Form and Table respectively.

// pseudocode
// e.g. for the form:
form.setsetItemDataSource(new BeanItem(mypojo));
// HostContainer extends BeanItemContainer:
getHostList().getContainerDataSource().addBean(mypojo);

Did this make any sense?

Best Regards,
Marc

I cannot use BeanItemContainer as the classes where generated by hyperjaxb and therefore contain fields like “hjid” I don’t want in my form.

But you put me into the right direction!

It seems that I cannot feed the HostList with the Item from the form, but I can feed the form with the Item from the HostList. That was the point.

Thanks for your help :slight_smile:

You can always use the form’s setVisibleItemProperties()-method to define which fields you want to show in your form. This way you can show whatever fields you want and hide fields such as “hjid”.

Ooops… you’re right :slight_smile: ty