title: Wicket: How to implement an IDataProvider/LoadableDetachableModel for indexed lists
body: <p>What's the best way to implement an <code>IDataProvider</code> and a <code>LoadableDetachable</code> in Wicket for an indexed list? Suppose I have a Customer who has a list of Adresses.</p>
  
  <pre><code>class Customer {
      List&lt;Adress&gt; adresses;
  }
  </code></pre>
  
  <p>Now I want to implement a data provider/ldm for the addresses of a customer. I suppose the usual way is an <code>IDataProvider</code> as an inner class which refers to the customer model of the component, like:</p>
  
  <pre><code>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());
  }
  
  }
  </code></pre>
  
  <p>Question: How would I implement this, when the address 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?</p>
  
  <p>In fact, I know a solution, but I wonder if there's a common pattern to do this.</p>