Hi Folks,
I’m trying to create some Form’s to edit an object which contains one-to-many attributes. e.g.
Entity(name = "Person")
public class Person extends ModelCore {
@Basic(optional = true)
private String firstName = null;
@Basic(optional = true)
private String lastName = null;
@OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true, targetEntity = Address.class)
@OrderColumn()
@JoinColumns({ @JoinColumn() })
private List<Address> addresses = new ArrayList<Address>();
}
@Entity(name = "Address")
public class Address extends ModelCore {
@Basic(optional = true)
private AddressType type = AddressType.WORK;
@ManyToOne(cascade = { CascadeType.ALL, CascadeType.PERSIST,
CascadeType.REFRESH }, optional = true, targetEntity = Country.class)
@JoinColumns({ @JoinColumn() })
private Country country = null;
@Basic(optional = true)
private String address1 = null;
@Basic(optional = true)
private String address2 = null;
What’s the best way of creating one or more Form’s to edit such data?
If I use the jpacontainer-demo as an example I would guess I do something like:
EntityItem<Person> person = ....;
final Form generalForm = new Form();
{
generalForm.setCaption("General information");
generalForm.setWriteThrough(true); // We use the buffering of the EntityItem instead
generalForm.setFormFieldFactory(fieldFactory);
generalForm.setItemDataSource(person);
generalForm.setVisibleItemProperties(new String[]{"firstName",
"lastName",
});
generalForm.setValidationVisible(true);
addComponent(generalForm);
}
for (Address addr : person.getAddresses()) {
Form billingForm = new Form();
billingForm.setCaption(" Address");
billingForm.setWriteThrough(true); // We use the buffering of the EntityItem instead
billingForm.setFormFieldFactory(fieldFactory);
billingForm.setItemDataSource(person);
billingForm.setVisibleItemProperties(new String[]{"????.address1",
"????.address2",});
billingForm.setValidationVisible(true);
addComponent(billingForm);
}
I’m not sure how to specify the values for setVisibleItemProperties() in the getAddresses() case. Is this even the right approach?
Alternatively I was thinking of implementing my own Forms independent of the JPAContainer and then saving the changes back to the datastore via my own DAO and then somehow notifying JPAContainer of the update. Not sure how to get JPAContainer() to recognize one of it’s managed objects has changed outside of it’s control, though.
Any suggestions/comments on either approach?
Thanks.
mike