I have asked a similar question before and not got a satisfactory answer, so i thought I’d rephrase things and give a simple, concrete exmaple.
I have two beans,
BeanOne and
BeanTwo . BeanOne contains a collection of BeanTwo, here is the code:
BeanOne
import java.util.Collection;
public class BeanOne {
private int ID;
private String name;
private Collection<BeanTwo> subbeans;
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Collection<BeanTwo> getSubbeans() {
return subbeans;
}
public void setSubbeans(Collection<BeanTwo> subbeans) {
this.subbeans = subbeans;
}
}
BeanTwo
public class BeanTwo {
private int ID;
private String name;
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
How do I get Vaadin to display a form for BeanOne which allows editing of the collection, including adding and removing BeanTwo instances and updating existing Instances? I want all the updates via the form to get written through to the orignal bean instances? I would prefer an out-of-the box solution, but am also happy to consider AddOns if neccessary.
Does anyone have a solution to this? Any help much appreciated.
You would probably find the
CustomField add-on useful.
There are examples of how to use nested forms to edit sub-items, and selecting existing BeanTwo instances for the set of references would be easy using FieldWrapper from the add-on around e.g. a TwinColSelect. However, you do need to write a little more code to also support the creation or editing of the sub-bean instances on the fly within the form.
Thanks for the information. I will look at the CustomField add-on today and see where it gets me. In my actual system I have 7 levels of nested collections so I hope CustomField will be able to cope with this without becoming brain-meltingly complex - here’s hoping
OK, I’ve managed to create the complete set of nested forms for all 7 tiers of my hierachy using EmbeddedForms and FieldWrappers. Still got some layout issues to work on but I’m confident these can be resolved. I’m also working on generisising the whole shbang so I can do it all with just two classes. I’ll post when/if I manage it.
Thanks for the assistance, thought this was going to be a real headache.