What's the best way to implement an IDataProvider and a LoadableDetachable in Wicket for an indexed list? Suppose I have a Customer who has a list of Adresses.
class Customer {
List adresses;
}
Now I want to implement a data provider/ldm for the adresses of a customer. I suppose the usual way is an IDataProvider as an inner class which refers to the customer model of the component, like:
class AdressDataProvider implements IDataProvider {
public Iterator iterator() {
Customer c = (Customer)Component.this.getModel(); // somehow get the customer model
return c.getAdresses().iterator();
}
public IModel model(Object o) {
Adress a = (Adress) o;
// Return an LDM which loads the adress by id.
return new AdressLoadableDetachableModel(a.getId());
}
}
Question: How would I implement this, when the adress does not have an ID (e.g. it's a Hibernate Embeddable/CollectionOfElements) but can only be identified by its index in the customer.adresses list? How do I keep reference to the owning entity and the index?
In fact, I know a solution, but I wonder if there's a common pattern to do this.