title: DropdownChoice selected not the same as model value, being changed on ajax update
body: <p>I have a listview and inside that listview is an</p>
  
  <p>EnumdropDrop - Textfield - DropdownChoice - Ajaxbutton | for every item</p>
  
  <p>The first dropdown is a currency and the second is an Account object, one of the choices in the account dropdown is to create a new Account which is then named after the currency.</p>
  
  <p>When the new account is created is should be the selected value in the account dropdown.</p>
  
  <p>This works fine for the first account, but the second and all subsequent newly created accounts are created correct and added to the list of possibilites but they are not the selected account. Everytime i make an ajax refresh the selected account in all newly created items are set as the first created account. The funny thing is when i submit the form, the account selections are correct.</p>
  
  <pre><code>package com.trifork.pengeplan.web.components.lists;
  
  import com.trifork.pengeplan.domain.*;
  import com.trifork.pengeplan.web.components.choice.EnumDropDownChoice;
  import com.trifork.pengeplan.web.components.choice.OwnedAccountCreateNewDropDownChoice;
  import org.apache.wicket.ajax.AjaxRequestTarget;
  import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
  import org.apache.wicket.markup.html.form.Form;
  import org.apache.wicket.markup.html.form.TextField;
  import org.apache.wicket.markup.html.list.ListItem;
  import org.apache.wicket.markup.html.list.PropertyListView;
  import org.apache.wicket.model.IModel;
  import org.apache.wicket.model.PropertyModel;
  import org.apache.wicket.model.ResourceModel;
  
  import java.util.List;
  
  /**
   * Created by IntelliJ IDEA.
   * User: tommysadiqhinrichsen
   * Date: 21/09/12
   * Time: 11.55
   */
  public class MultipleCurrenciesListView extends PropertyListView&lt;FinanceAccountCurrencyMapping&gt; {
  
      IModel&lt;OwnedAccount&gt; ownedAccountIModel;
  
      public MultipleCurrenciesListView(String id, IModel model) {
          super(id, new PropertyModel&lt;List&lt;FinanceAccountCurrencyMapping&gt;&gt;(model, "financeAccountCurrencyMappings"));
          ownedAccountIModel = model;
  
      }
  
      @Override
      protected void populateItem(final ListItem&lt;FinanceAccountCurrencyMapping&gt; item) {
  
          EnumDropDownChoice&lt;MoneyCurrency&gt; moneyCurrency = new EnumDropDownChoice&lt;MoneyCurrency&gt;("moneyCurrency");
          moneyCurrency.add(new AjaxFormComponentUpdatingBehavior("onchange") {
              @Override
              protected void onUpdate(AjaxRequestTarget target) {
                  MoneyCurrency moneyCurrency = (MoneyCurrency) getFormComponent().getModelObject();
              }
          });
          item.add(moneyCurrency);
  
          item.add(new TextField("financeAccount.accountNumber"));
  
          final OwnedAccountCreateNewDropDownChoice accountForCash = new OwnedAccountCreateNewDropDownChoice("accountForCash", ownedAccountIModel.getObject().getLegalEntity().getOwnedBankAccounts());
  
          accountForCash.add(new AjaxFormComponentUpdatingBehavior("onchange") {
              @Override
              protected void onUpdate(AjaxRequestTarget target) {
                  OwnedAccount ownedAccount = (OwnedAccount) getFormComponent().getModelObject();
                  if (ownedAccount != null &amp;&amp; ownedAccount.getId() == -1) {
  
                      OwnedAccount newOwnedAccount = new OwnedAccount();
                      FinanceAccountCurrencyMapping financeAccountCurrencyMapping = item.getModelObject();
                      financeAccountCurrencyMapping.setAccountForCash(ownedAccount);
  
                      newOwnedAccount.setName(financeAccountCurrencyMapping.getOwnedAccount().getName() + " - " + financeAccountCurrencyMapping.getMoneyCurrency().name());
                      newOwnedAccount.setLegalEntity(financeAccountCurrencyMapping.getOwnedAccount().getLegalEntity());
                      newOwnedAccount.setAssetOrLiability(AssetOrLiability.ASSET);
                      newOwnedAccount.setAssetType(AssetType.BANK_ACCOUNT);
                      newOwnedAccount.setCurrency(financeAccountCurrencyMapping.getMoneyCurrency());
                      newOwnedAccount.getFinanceAccountCurrencyMappings().add(new FinanceAccountCurrencyMapping(newOwnedAccount));
                      ownedAccountIModel.getObject().getLegalEntity().getOwnedAccounts().add(ownedAccountIModel.getObject().getLegalEntity().getOwnedAccounts().size() - 1, newOwnedAccount);
  
                      accountForCash.setDefaultModelObject(newOwnedAccount);
  
                      target.add(getFormComponent().getForm().getPage());
  
                  }
  
  
              }
          });
          item.add(accountForCash);
  
  
          item.add(new AjaxButton("deleteFinanceAccount", new ResourceModel("button.delete")) {
              @Override
              protected void onSubmit(AjaxRequestTarget target, Form&lt;?&gt; form) {
                  ownedAccountIModel.getObject().getFinanceAccountCurrencyMappings().remove(item.getModelObject());
                  target.add(this.getForm());
              }
  
              @Override
              protected void onError(AjaxRequestTarget target, Form&lt;?&gt; form) {
                  super.onError();
              }
          });
      }
  
  
  }
  </code></pre>
  
  <p>Can someone tell me what the problem is?</p>
  
  <p><img src="https://i.stack.imgur.com/53yQS.png" alt="Created first account">
  <img src="https://i.stack.imgur.com/eZdOC.png" alt="Created second account">
  <img src="https://i.stack.imgur.com/IRvJ4.png" alt="About to create third account">
  <img src="https://i.stack.imgur.com/xwwLV.png" alt="Created third account but not selecte">
  <img src="https://i.stack.imgur.com/oQI3w.png" alt="Refresh reset all">
  <img src="https://i.stack.imgur.com/BUGpB.png" alt="Saved values from image 5"></p>
  
  <p>UPDATED </p>
  
  <pre><code>package com.trifork.pengeplan.web.components.choice;
  
  import com.trifork.pengeplan.domain.OwnedAccount;
  import org.apache.wicket.markup.html.form.ChoiceRenderer;
  import org.apache.wicket.markup.html.form.DropDownChoice;
  import org.apache.wicket.model.IModel;
  import org.apache.wicket.model.Model;
  import org.apache.wicket.model.PropertyModel;
  import org.apache.wicket.model.ResourceModel;
  
  import java.util.List;
  
  /**
   * Created by IntelliJ IDEA.
   * User: tommysadiqhinrichsen
   * Date: 18/09/12
   * Time: 16.01
   * To change this template use File | Settings | File Templates.
   */
  public class OwnedAccountCreateNewDropDownChoice extends DropDownChoice&lt;OwnedAccount&gt; {
  
      public OwnedAccountCreateNewDropDownChoice(String id) {
          super(id);
          List&lt;OwnedAccount&gt; choices = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
          setChoices(choices);
          init();
      }
  
      public OwnedAccountCreateNewDropDownChoice(String id, IModel model) {
          super(id, model);
          List&lt;OwnedAccount&gt; choices = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
          setChoices(choices);
          init();
  
      }
  
      public OwnedAccountCreateNewDropDownChoice(String id, List&lt;OwnedAccount&gt; choices) {
          super(id, choices);
          List&lt;OwnedAccount&gt; choices1 = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
          setChoices(choices);
          init();
      }
  
      public OwnedAccountCreateNewDropDownChoice(String id, List&lt;OwnedAccount&gt; choices, ChoiceRenderer&lt;OwnedAccount&gt; renderer) {
          super(id, choices, renderer);
          List&lt;OwnedAccount&gt; choices2 = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
          setChoices(choices);
          init();
      }
  
      public OwnedAccountCreateNewDropDownChoice(String id, Model&lt;OwnedAccount&gt; model, List&lt;OwnedAccount&gt; choices, ChoiceRenderer&lt;OwnedAccount&gt; renderer) {
          super(id, model, choices, renderer);
          List&lt;OwnedAccount&gt; choices3 = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
          setChoices(choices);
          init();
      }
  
      public OwnedAccountCreateNewDropDownChoice(String id, PropertyModel&lt;OwnedAccount&gt; model, List&lt;OwnedAccount&gt; choices, ChoiceRenderer&lt;OwnedAccount&gt; renderer) {
          super(id, model, choices, renderer);
          List&lt;OwnedAccount&gt; choices4 = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
          setChoices(choices);
          init();
      }
  
  
      public void init() {
  
      }
  
      public void addChoice(OwnedAccount ownedAccount) {
  
          List&lt;OwnedAccount&gt; choices = (List&lt;OwnedAccount&gt;) getChoices();
          choices.add(choices.size() - 1, ownedAccount);
          setChoices(choices);
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/BZQzf.png" alt="Ajax response"></p>