title: Autocomplete using advanced model in wicket
body: <p>First I want to say I saw a site:<br />
  <a href="https://cwiki.apache.org/WICKET/autocomplete-using-a-wicket-model.html" rel="nofollow">https://cwiki.apache.org/WICKET/autocomplete-using-a-wicket-model.html</a><br /></p>
  
  <p>Still I have some problem with implementation.</p>
  
  <p><strong>Context</strong><br />
  I have form where want to edit Order from my database. 
  I want to autocomplete client's name in form and save it to database. </p>
  
  <p><strong>Problem</strong><br />
  I can see suggestions of client names and I can choose which client's name I'll use.
  Just when I submit form new client won't be saved in order, in database.
  I don't know how to relate form Model with AutoCompleteTextField input.</p>
  
  <p>Any ideas ?</p>
  
  <p>Pseudo code of my classes:</p>
  
  <pre><code>Order{
    Long id;
    String date;
    Client client;
    Status status;
    ...
  }
  
  Client{
    Long id;
    String name;
    String nip;
    String address;
    String postcode;
    String city;
    String phone;
    String mail;
    ...
  }
  
  Status{
     Long id;
     String name;
     String value;
  }
  </code></pre>
  
  <p><strong>Edited:</strong><br />
  Yes you are right.</p>
  
  <p>My implementation of AbstractAutoCompleteTextField from site:</p>
  
  <pre><code>AbstractAutoCompleteRenderer autoCompleteRenderer = new AbstractAutoCompleteRenderer() {
  
                  protected final String getTextValue(final Object object) {
                      Client client = (Client) object;
                      return client.getName();
                  }
  
                  protected final void renderChoice(final Object object, final Response response, final String criteria) {
                      response.write(getTextValue(object));
                  }
  
              };
  
  
              // textfield
              AbstractAutoCompleteTextField&lt;Client&gt; name = new AbstractAutoCompleteTextField&lt;Client&gt;("name", new PropertyModel(order, "client"), autoCompleteRenderer) {
  
                  protected final List&lt;Client&gt; getChoiceList(final String input) {
                      return clientService.findByNames(10, 0, input);
                  }
  
                  protected final String getChoiceValue(final Client choice) throws Throwable {
                      return choice.getId().toString();
                  }
              };
  form.add(name);
  </code></pre>
  
  <p>My form implementation you asked for:</p>
  
  <pre><code>form = new Form("orderForm", new CompoundPropertyModel(order)) {
              @Override
              public void onSubmit() {
                  orderService.update((Order) getDefaultModelObject());
                  setResponsePage(OrdersPage.class);
                  // Form validation successful. Display message showing edited
                  // model.
              }
          };
  </code></pre>
  
  <p>With this code I got: "'Hurtownia Techniczna "ADA"' is not proper Client." (translated from Polish) in feedback panel.</p>