Wicket: How to implement an IDataProvider/LoadableDetachableModel for indexed lists

Posted by cretzel on Stack Overflow See other posts from Stack Overflow or by cretzel
Published on 2008-12-15T11:03:48Z Indexed on 2010/04/02 22:03 UTC
Read the original article Hit count: 286

Filed under:

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.

© Stack Overflow or respective owner

Related posts about wicket