一部のmodelObjectを親ページとして使用するパネルを取得するにはどうすればよいですか?
モデルとしてOwnedAccountを使用するフォームがあり、そのフォームには、financeAccountのリストを含むrefreshingviewを持つカスタムパネルがあります。問題は、financeaccountsへの変更がフォームのmodelobjectで変更されていないことです。
いくつかのコード、私は3つのドット「...」がある多くのコードを削除しました
@Entity
@Table(name = "ownedaccount")
public class OwnedAccount implements Serializable {
...
//used for multiple currencies
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "ownedAccount")
private List<FinanceAccount> financeAccounts = new ArrayList<FinanceAccount>();
...
}
public class AssetsPage extends LoggedInPage {
...
// bookmarkable constructor
public AssetsPage(PageParameters parameters) {
super(parameters);
init();
}
private void init() {
final OwnedAccount ownedAccount = getCurrentSelections().getSelectedOwnedAccount();
add(new FeedbackPanel("feedback"));
entityEdit = new OwnedAccountForm("entityEdit", ownedAccount);
add(entityEdit);
}
@Override
protected void selectionsChanged() {
OwnedAccount selectedOwnedAccount = getCurrentSelections().getSelectedOwnedAccount();
CompoundPropertyModel<OwnedAccount> model = new CompoundPropertyModel<OwnedAccount>(selectedOwnedAccount);
entityEdit.setModel(model);
}
...
class OwnedAccountForm extends BaseCreateEditForm<OwnedAccount, Void> {
...
public OwnedAccountForm(String s, OwnedAccount entity) {
super(s, entity, null);
assetType = entity.getAssetType();
}
@Override
protected void initComponents(Void initParams) {
...
multipleCurrenciesPanel = new MultipleCurrenciesPanel("multipleCurrenciesPanel", ownedAccountService, getCurrentSelections());
add(multipleCurrenciesPanel);
...
}
...
}
public class MultipleCurrenciesPanel extends Panel {
OwnedAccountService ownedAccountService;
CurrentSelections currentSelections;
public MultipleCurrenciesPanel(String id, OwnedAccountService ownedAccountService, CurrentSelections currentSelections) {
super(id);
this.ownedAccountService = ownedAccountService;
this.currentSelections = currentSelections;
init();
}
private void init() {
DepositoryLabel currencyLabel = new DepositoryLabel("currency", new ResourceModel("currency"));
add(currencyLabel);
DepositoryLabel accountForSecuritasLabel = new DepositoryLabel("account.for.securitas", new ResourceModel("account.for.securitas"));
add(accountForSecuritasLabel);
DepositoryLabel accountForCashLabel = new DepositoryLabel("account.for.cash", new ResourceModel("account.for.cash"));
add(accountForCashLabel);
DepositoryLabel buttonDeleteLabel = new DepositoryLabel("button.delete", new ResourceModel("button.delete"));
add(buttonDeleteLabel);
CurrenciesView currenciesView = new CurrenciesView("financeAccounts", ownedAccountService, currentSelections, this);
add(currenciesView);
setOutputMarkupId(true);
}
}
25/9-15:15更新
public class CurrenciesView extends RefreshingView<FinanceAccount> {
private OwnedAccountService ownedAccountService;
private CurrentSelections currentSelections;
private WebMarkupContainer multipleCurrenciesForDepot;
public CurrenciesView(String id, OwnedAccountService ownedAccountService, CurrentSelections currentSelections, WebMarkupContainer multipleCurrenciesForDepot) {
super(id);
this.ownedAccountService = ownedAccountService;
this.currentSelections = currentSelections;
this.multipleCurrenciesForDepot = multipleCurrenciesForDepot;
}
@Override
protected Iterator getItemModels() {
List<FinanceAccount> financeAccounts = ownedAccountService.getFinanceAccounts(currentSelections.getSelectedOwnedAccount());
return new ModelIteratorAdapter<FinanceAccount>(financeAccounts.iterator()) {
@Override
protected IModel<FinanceAccount> model(FinanceAccount object) {
return new CompoundPropertyModel<FinanceAccount>((object));
}
};
}
@Override
protected void populateItem(Item<FinanceAccount> item) {
final FinanceAccount financeAccount = item.getModelObject();
item.add(new EnumDropDownChoice<MoneyCurrency>("forCurrency"));
item.add(new TextField("accountNumber"));
item.add(new OwnedAccountDropDownChoice("accountForCash", currentSelections.getSelectedLegalEntity().getOwnedBankAccounts()));
item.add(new AjaxButton("deleteFinanceAccount") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
//TODO Delete finance account
ownedAccountService.deleteFinanceAccount(currentSelections.getSelectedOwnedAccount(), financeAccount);
target.add(multipleCurrenciesForDepot);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
//TODO create error message
}
});
}
}