Gateway: How to Implement IDataProvider / LoadableDetachableModel for Indexed Lists
What's the best way to implement IDataProvider
and LoadableDetachable
in Wicket for an indexed list? Suppose I have a Client who has a list of Addresses.
class Customer {
List<Adress> adresses;
}
Now I want to implement a data provider / ldm for client addresses. I suppose the usual way is IDataProvider
as an inner class that refers to the client model of the component, for example:
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 to implement this when the address does not have an ID (for example, it is Hibernate Embeddable / CollectionOfElements) but can only be identified by its index in the customer.adresses list? How do I preserve the owning entity reference and index?
Actually, I know a solution, but I'm wondering if there is a general pattern for this.
source to share
What's your suggested solution? Your question seems not entirely clear to me. Are the addresses loaded with lazy sleepers? I can't figure out what your problem is with the above code. If your addresses are loaded into Hibernate at c.getAdresses (). Iterator (); call, then you have addresses and what's the problem? Is customer.adresses actually a list of address objects, or just id? You can always write your own object and index it inside your AdressLoadableDetachableModel ie AdressLoadableDetachableModel (a.getId (), (Customer) Component.this.getModel ()) Can you help clarify?
source to share