Best practice - Form with an attached container

Hi,

I am looking for a best practice regarding the creation of new entries. Say that I have a ServerConfiguration (with a type, a name, an url, etc) and a ServerConfigurationContainer. I have one implementation that is backed by BeanItemContainer and is supposed to save the state of all configurations in an XML file.

In my application, I have a button “Create” that is supposed to show a form and add the created configuration when the user hits save.

I got it working but it feels “weird”. I was expecting the container abstraction to provide more integration so I probably have done something wrong.

When I initialize my form, I do something like this:

 form.setItemDataSource(
                new BeanItem<ServerConfiguration>(new GenericServerConfiguration()));

When the user clicks on “Save”, I have something like this

if (isValid()) {
  commit();
  panel.getContainer().addItem(
         ((BeanItem<ServerConfiguration>) getItemDataSource()).getBean());
           getWindow().showNotification("Added server configuration");
           setReadOnly(true);
 }
  • Can I just “attach” the container to my form and when it’s initialized it has an empty object in it and a call to commit would simply add a new instance to the container?
  • Say that I want to make sure that the name of a configuration is unique within my container. Should I add a custom validator that loops over the container and checks if one instance already exists with that name (the container is not private to the user, it’s a global configuration for any admin using the application)
  • What is the best hook point on the container interface to flush new changes in my xml file?

Thanks for the input!

any idea?