【发布时间】:2013-01-13 05:33:31
【问题描述】:
-
我有一个 java 类:
public Task { private int id; private Company sender; private Company receiver; //Getter and Setter ... }如您所见,我在任务类中还有另外 2 个自定义类。例如,公司有地址和目录。
-
我有一个可在页面上重复使用的 CompanyPanel。这是面板中的一些代码。
public class CompanyPanel extends Panel { protected List<Company> companies; public CompanyPanel(String id, IModel<Company> model) { super(id,new CompoundPropertyModel<Company>(model)); companies = new ArrayList<Company>(); Company company_1 = new Company(); //Setting default predefined values for the company, so I can select it from the dropdown and to set fields automatically company_1.setFtpAdress("adress1.com"); company_1.setFtpDir("/MusterDir/"); companies.add(company_1); //SAME for another company ... companies.add(comany_2); ... final DropDownChoice<Company> companyList = new DropDownChoice<Company>("companies", model, new LoadableDetachableModel<List<Company>>() { @Override protected List<Company> load() { return companies; } }){ protected boolean wantOnSelectionChangedNotifications() { return true; } }; add(companyList); final TextField<String> ftpAdress = new TextField<String>("ftpAdress"); ftpAdress.setOutputMarkupId(true); add(ftpAdress); final TextField<String> ftpDir = new TextField<String>("ftpDir"); ftpDir.setOutputMarkupId(true); add(ftpDir); //added Ajax to dropdown to update textfields automatically, based on selection of dropdown companyList.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { target.add(ftpAdress); target.add(ftpDir); } }); } } -
在页面中,我使用可重复使用的 CompanyPanel。
... CompanyPanel senderPanel = new CompanyPanel("senderPanel", new PropertyModel(task,"sender")); senderPanel.setOutputMarkupId(true); form.add(senderPanel); CompanyPanel receiverPanel = new CompanyPanel("receiverPanel", new PropertyModel(task,"receiver")); receiverPanel.setOutputMarkupId(true); form.add(receiverPanel); ... -
当我提交表单时:
public void onSubmit(AjaxRequestTarget target, Form<?> form) { //doSomething target.add(senderPanel); target.add(receiverPanel); }
问题:公司面板没有被重新渲染。我真的不知道为什么。
工作流程:
- 我从下拉面板中选择了一家公司
- 将根据下拉菜单正确设置 TextFields(位于 companyPanel 内)
- 我修改了一个textField(属于一家公司)
- 我提交表单
- 我从下拉列表中更改公司
- 我改回第一家公司 -> 问题:修改后的文本字段仍显示修改后的文本。它未重置为默认值。
非常感谢任何帮助。
【问题讨论】:
-
我看到您也将此面板添加到您的表单中。什么时候第一次显示页面,然后你可以看到这个面板?
-
是否首先调用了 onSubmit 方法?如果有验证器触发,则调用 onError 方法。
-
你在 CompanyPanel 做什么?
-
@hudi 是的,当页面加载时我可以看到所有的面板
-
@Nicktar onSubmit 方法首先被调用,是的,当用户点击按钮时
标签: ajax refresh wicket panel reusability