Java 选择的DropdownChoice与模型值不同,在ajax更新时更改
我有一个listview,在该listview中有一个 EnumdropDrop-Textfield-DropdownChoice-Ajaxbutton |用于每个项目 第一个下拉列表是货币,第二个是帐户对象,帐户下拉列表中的一个选项是创建一个新帐户,然后以货币命名 创建新帐户时,应为帐户下拉列表中的选定值 这对于第一个帐户很有效,但是第二个和所有后续新创建的帐户都被正确创建并添加到可能性列表中,但它们不是所选的帐户。每次我进行ajax刷新时,所有新创建的项目中的选定帐户都被设置为第一个创建的帐户。有趣的是,当我提交表单时,帐户选择是正确的Java 选择的DropdownChoice与模型值不同,在ajax更新时更改,java,ajax,wicket,Java,Ajax,Wicket,我有一个listview,在该listview中有一个 EnumdropDrop-Textfield-DropdownChoice-Ajaxbutton |用于每个项目 第一个下拉列表是货币,第二个是帐户对象,帐户下拉列表中的一个选项是创建一个新帐户,然后以货币命名 创建新帐户时,应为帐户下拉列表中的选定值 这对于第一个帐户很有效,但是第二个和所有后续新创建的帐户都被正确创建并添加到可能性列表中,但它们不是所选的帐户。每次我进行ajax刷新时,所有新创建的项目中的选定帐户都被设置为第一个创建的帐
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();
}
});
}
}
package com.trifork.pengeplan.web.components.lists;
导入com.trifork.pengeplan.domain.*;
导入com.trifork.pengeplan.web.components.choice.EnumDropDownChoice;
导入com.trifork.pengeplan.web.components.choice.OwnedAccountCreateNewDropDownChoice;
导入org.apache.wicket.ajax.AjaxRequestTarget;
导入org.apache.wicket.ajax.form.ajaxFormComponentUpdateBehavior;
导入org.apache.wicket.ajax.markup.html.form.AjaxButton;
导入org.apache.wicket.markup.html.form.form;
导入org.apache.wicket.markup.html.form.TextField;
导入org.apache.wicket.markup.html.list.ListItem;
导入org.apache.wicket.markup.html.list.PropertyListView;
导入org.apache.wicket.model.IModel;
导入org.apache.wicket.model.PropertyModel;
导入org.apache.wicket.model.ResourceModel;
导入java.util.List;
/**
*由IntelliJ IDEA创建。
*用户:tommysadiqhinrichsen
*日期:2012年9月21日
*时间:11时55分
*/
公共类MultipleCurrenciesListView扩展了PropertyListView{
IModel拥有的会计模型;
公共MultipleCrenciesListView(字符串id,IModel模型){
超级(id,新PropertyModel(模型,“financeAccountCurrencyMappings”);
OwnedAccountModel=模型;
}
@凌驾
受保护的无效填充项(最终列表项){
EnumDropDownChoice moneyCurrency=新的EnumDropDownChoice(“moneyCurrency”);
moneyCurrency.add(新的AjaxFormComponentUpdateBehavior(“onchange”){
@凌驾
受保护的void onUpdate(AjaxRequestTarget目标){
MoneyCurrency=(MoneyCurrency)getFormComponent().getModelObject();
}
});
项目.添加(货币);
添加(新文本字段(“financeAccount.accountNumber”);
最终OwnedAccountCreateNewDropDownChoice accountForCash=新OwnedAccountCreateNewDropDownChoice(“accountForCash”,OwnedAccountModel.getObject().getLegalEntity().getOwnedBankAccounts());
accountForCash.add(新的AjaxFormComponentUpdateBehavior(“onchange”){
@凌驾
受保护的void onUpdate(AjaxRequestTarget目标){
OwnedAccount OwnedAccount=(OwnedAccount)getFormComponent().getModelObject();
if(ownedAccount!=null&&ownedAccount.getId()=-1){
OwnedAccount newOwnedAccount=新OwnedAccount();
FinanceAccountCurrencyMapping FinanceAccountCurrencyMapping=item.getModelObject();
financeAccountCurrencyMapping.setAccountForCash(ownedAccount);
newOwnedAccount.setName(financeAccountCurrencyMapping.getOwnedAccount().getName()+“-”+financeAccountCurrencyMapping.GetMoneyCurrencyMapping().name());
newOwnedAccount.setLegalEntity(financeAccountCurrencyMapping.getOwnedAccount().getLegalEntity());
新拥有的账户。设置资产负债(资产负债。资产);
newOwnedAccount.setAssetType(资产类型.银行账户);
newOwnedAccount.setCurrency(financeAccountCurrencyMapping.getMoneyCurrency());
newOwnedAccount.getFinanceAccountCurrencyMappings().add(newFinanceAccountCurrencyMapping(newOwnedAccount));
OwnedAccountModel.getObject().getLegalEntity().getOwnedAccounts().add(OwnedAccountModel.getObject().getLegalEntity().getOwnedAccounts().size()-1,newOwnedAccount);
accountForCash.setDefaultModelObject(newOwnedAccount);
add(getFormComponent().getForm().getPage());
}
}
});
项目.添加(账户现金);
添加项目(新的AjaxButton(“删除财务帐户”),新的ResourceModel(“button.delete”)){
@凌驾
提交时受保护的void(AjaxRequestTarget目标,表单){
OwnedAccountModel.getObject().getFinanceAccountCurrencyMappings().remove(item.getModelObject());
add(this.getForm());
}
@凌驾
受保护的void onError(AjaxRequestTarget目标,表单){
super.onError();
}
});
}
}
有人能告诉我问题出在哪里吗
更新
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);
}
}
package com.trifork.pengeplan.web.components.choice;
导入com.trifork.pengeplan.domain.OwnedAccount;
导入org.apache.wicket.markup.html.form.ChoiceRenderer;
导入org.apache.wicket.markup.html.form.DropDownChoice;
导入org.apache.wicket.model.IModel;
导入org.apache.wicket.model.model;
导入org.apache.wicket.model.PropertyModel;
导入org.apache.wicket.model.ResourceModel;
导入java.util.List;
/**
*由IntelliJ IDEA创建。
*用户:tommysadiqhinrichsen
*日期:2012年9月18日
*时间:16时01分
*要更改此模板,请使用文件|设置|文件模板。
*/
公共类OwnedAccountCreateNewDropDownChoice扩展了DropDownChoice{
公有帐户CreateNewDropDownChoice(字符串id){
超级(id);
列表选项=(列表)getChoices();
add(newownedAccount(-1,newResourceModel(“create.new”).getObject());
设置选项(选项)
new OwnedAccountCreateNewDropDownChoice("accountForCash",
ownedAccountIModel.getObject().getLegalEntity().getOwnedBankAccounts());
new OwnedAccountCreateNewDropDownChoice("accountForCash",
new PropertyModel(ownedAccountIModel, "legalEntity.ownedBankAccounts");