Java 面板使用与父页面相同的模型
如何获得一个面板以使用某个modelObject作为父页面 我有一个使用OwnedAccount作为模型的表单,在表单中我有一个自定义面板,其中有一个包含financeAccount列表的刷新视图。问题是表单的modelobject中没有更改对financeaccounts的更改 一些代码,我删除了很多有3个点的代码“…”Java 面板使用与父页面相同的模型,java,model,wicket,Java,Model,Wicket,如何获得一个面板以使用某个modelObject作为父页面 我有一个使用OwnedAccount作为模型的表单,在表单中我有一个自定义面板,其中有一个包含financeAccount列表的刷新视图。问题是表单的modelobject中没有更改对financeaccounts的更改 一些代码,我删除了很多有3个点的代码“…” 更新日期:25/9-15:15 public class CurrenciesView extends RefreshingView<FinanceAccount&g
更新日期: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
}
});
}
}
公共类currenceView扩展了RefreshingView{
私人拥有的会计服务拥有的会计服务;
私有当前选择当前选择;
私有WebMarkupContainer Multipleurenciesfordepot;
公共货币视图(字符串id、OwnedAccountService OwnedAccountService、CurrentSelections CurrentSelections、WebMarkupContainer MultipleurenciesForDepot){
超级(id);
this.ownedAccountService=ownedAccountService;
this.currentSelections=currentSelections;
this.multipleCurrenciesForDepot=multipleCurrenciesForDepot;
}
@凌驾
受保护的迭代器getItemModels(){
List financeAccounts=ownedAccountService.getFinanceAccounts(currentSelections.getSelectedOwnedAccount());
返回新的ModelIteratorAdapter(financeAccounts.iterator()){
@凌驾
受保护的IModel模型(FinanceAccount对象){
返回新的CompoundPropertyModel((对象));
}
};
}
@凌驾
受保护的无效填充项(项){
final FinanceAccount FinanceAccount=item.getModelObject();
添加(新的EnumDropDownChoice(“forCurrency”);
添加(新文本字段(“帐号”));
添加(新的OwnedAccountDropDownChoice(“accountForCash”,currentSelections.getSelectedLegalEntity().getOwnedBankAccounts());
添加项目(新的AJAX按钮(“删除财务账户”){
@凌驾
提交时受保护的void(AjaxRequestTarget目标,表单){
//TODO删除财务帐户
ownedAccountService.deleteFinanceAccount(currentSelections.getSelectedOwnedAccount(),financeAccount);
target.add(multiplecurrencesforepot);
}
@凌驾
受保护的void onError(AjaxRequestTarget目标,表单){
//TODO创建错误消息
}
});
}
}
如果两个不同的wicket页面/组件使用和屏蔽CurrentSelections,则需要对其进行建模
例如,有一个父页面,它有一个构造函数、一个新的String对象和一个使用String对象作为参数的面板
public class ParentPage extends WebPage {
public ParentPage() {
String string = new String("Dave");
add(new Panel("childPanel", string));
string = new String("Brian");
}
}
如果在添加面板后更新字符串对象,则更新的字符串不是面板所具有的字符串。当认为ParentPage现在的字符串是“Brian”时,面板上显示的是“Dave”
但是,如果我们制作了一个模型并使其使用string对象,那么当我们更改字符串时,childPanel将得到更新
public class ParentPage extends WebPage {
public ParentPage() {
String string = new String("Dave");
IModel model = new Model(string);
add(new Panel("childPanel", model));
model.setObject(new String("Brian"));
}
}
这是一个非常简单的示例,但我希望它能有所帮助。我将在构造函数中传递的模型引用保存到面板中,到目前为止,它工作正常
BankAccountPanel bankAccountPanel = new BankAccountPanel("bankAccountPanel", getModel());
add(bankAccountPanel);
公共类BankAccountPanel扩展面板{
伊莫代尔;
public BankAccountPanel(字符串id,IModel模型){
超级(id,型号);
this.iModel=模型;
init();
}
Hi,我看不到您更改financeaccounts的代码。无论如何,您应该避免在不使用模型的情况下将数据对象直接传递给组件。这通常会导致对数据对象当前状态的一些混淆,因为您不知道如何“刷新”是的。Andrea是对的,你应该只在对象周围传递一个模型!你能举例说明你的意思吗,我会在原始代码下面发布financeaccounts的代码。传递给MultipleCurrencesPanel的currentSelections对象应该是一个模型。如果你的父类中的对象有任何更改s、 多发性电子信号板内的那一个已经过时了。
public class ParentPage extends WebPage {
public ParentPage() {
String string = new String("Dave");
add(new Panel("childPanel", string));
string = new String("Brian");
}
}
public class ParentPage extends WebPage {
public ParentPage() {
String string = new String("Dave");
IModel model = new Model(string);
add(new Panel("childPanel", model));
model.setObject(new String("Brian"));
}
}
BankAccountPanel bankAccountPanel = new BankAccountPanel("bankAccountPanel", getModel());
add(bankAccountPanel);
public class BankAccountPanel extends Panel {
IModel<OwnedAccount> iModel;
public BankAccountPanel(String id, IModel<OwnedAccount> model) {
super(id, model);
this.iModel = model;
init();
}