Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:52:02+00:00 2026-06-14T21:52:02+00:00

I have a listview and inside that listview is an EnumdropDrop – Textfield –

  • 0

I have a listview and inside that listview is an

EnumdropDrop – Textfield – DropdownChoice – Ajaxbutton | for every item

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.

When the new account is created is should be the selected value in the account dropdown.

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.

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<FinanceAccountCurrencyMapping> {

    IModel<OwnedAccount> ownedAccountIModel;

    public MultipleCurrenciesListView(String id, IModel model) {
        super(id, new PropertyModel<List<FinanceAccountCurrencyMapping>>(model, "financeAccountCurrencyMappings"));
        ownedAccountIModel = model;

    }

    @Override
    protected void populateItem(final ListItem<FinanceAccountCurrencyMapping> item) {

        EnumDropDownChoice<MoneyCurrency> moneyCurrency = new EnumDropDownChoice<MoneyCurrency>("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 && 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<?> form) {
                ownedAccountIModel.getObject().getFinanceAccountCurrencyMappings().remove(item.getModelObject());
                target.add(this.getForm());
            }

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                super.onError();
            }
        });
    }


}

Can someone tell me what the problem is?

Created first account
Created second account
About to create third account
Created third account but not selecte
Refresh reset all
Saved values from image 5

UPDATED

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<OwnedAccount> {

    public OwnedAccountCreateNewDropDownChoice(String id) {
        super(id);
        List<OwnedAccount> choices = (List<OwnedAccount>) getChoices();
        choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
        setChoices(choices);
        init();
    }

    public OwnedAccountCreateNewDropDownChoice(String id, IModel model) {
        super(id, model);
        List<OwnedAccount> choices = (List<OwnedAccount>) getChoices();
        choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
        setChoices(choices);
        init();

    }

    public OwnedAccountCreateNewDropDownChoice(String id, List<OwnedAccount> choices) {
        super(id, choices);
        List<OwnedAccount> choices1 = (List<OwnedAccount>) getChoices();
        choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
        setChoices(choices);
        init();
    }

    public OwnedAccountCreateNewDropDownChoice(String id, List<OwnedAccount> choices, ChoiceRenderer<OwnedAccount> renderer) {
        super(id, choices, renderer);
        List<OwnedAccount> choices2 = (List<OwnedAccount>) getChoices();
        choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
        setChoices(choices);
        init();
    }

    public OwnedAccountCreateNewDropDownChoice(String id, Model<OwnedAccount> model, List<OwnedAccount> choices, ChoiceRenderer<OwnedAccount> renderer) {
        super(id, model, choices, renderer);
        List<OwnedAccount> choices3 = (List<OwnedAccount>) getChoices();
        choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
        setChoices(choices);
        init();
    }

    public OwnedAccountCreateNewDropDownChoice(String id, PropertyModel<OwnedAccount> model, List<OwnedAccount> choices, ChoiceRenderer<OwnedAccount> renderer) {
        super(id, model, choices, renderer);
        List<OwnedAccount> choices4 = (List<OwnedAccount>) getChoices();
        choices.add(new OwnedAccount(-1, new ResourceModel("create.new").getObject()));
        setChoices(choices);
        init();
    }


    public void init() {

    }

    public void addChoice(OwnedAccount ownedAccount) {

        List<OwnedAccount> choices = (List<OwnedAccount>) getChoices();
        choices.add(choices.size() - 1, ownedAccount);
        setChoices(choices);
    }
}

Ajax response

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:52:03+00:00Added an answer on June 14, 2026 at 9:52 pm

    I found the problem 🙂

    Listviews are not good in forms because the can’t handle dynamic changes because the list items dont keep track of their index.

    I’ve implemented a listview based on a guide found at this website

    http://wicketinaction.com/2008/10/building-a-listeditor-form-component/

    I works like a charm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can we have ExpandableListView inside ListView so that I can have group level first
I have a ListView inside a FormView that, for some strange reason, doesn't fire
I have a ListView inside a AlertDialog, the problem I am having is that
What I essentially have is tabview with a listview inside. When an item in
I have a ListView with a checkbox field inside that gets the id set
I have a WPF ListView inside StackPanel, with Height=Auto. It's great that it does
I have a WPF ListView inside StackPanel, with Height=Auto. It's great that it does
I have created a listview that sits inside a larger activity (the list view
Possible Duplicate: Getting value of a PasswordBox that's inside a ListView I have a
I have a ListView that I'm populating from a custom ListAdapter . Inside the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.