Wicket-具有Java继承的可重用面板 [英] Wicket - Reusable panels with java inheritance
问题描述
-
我有以下Java类:
I have following java classes:
我有两个表单组件,它们使用CompoundPropertyModel映射到Type1Task和Type2Task:
I have a two form components which are mapped to Type1Task and Type2Task with a CompoundPropertyModel:
问题:重复的代码.我希望D和E字段映射到任务,而不是任务类型.我拥有Java继承时,有什么方法可以使它可重用?
如果可以,您能给我提供教程或参考资料吗?
If yes, can u provide me with tutorials or references?
其他信息:任务可以包含一个计时器(线程).如果单击提交按钮,计时器将启动.
Additional info: The task can contain a timer(thread). If you click on submit button the timer will be started.
谢谢!
推荐答案
您可以在ui中复制相同的类层次结构.
You can duplicate the same class hierarchy in the ui.
public class TaskFormPanel<T extends Task> extends Panel {
public TaskFormPanel(String id, IModel<T> model)
super(id, new CompoundPropertyModel(model));
add(new TextField("d"));
add(new TextField("e));
add(new Button("submit) {
(...)
}
}
}
public class Task1FormPanel extends TaskFormPanel<Task1> {
public TaskFormPanel(String id, IModel<Task1> model)
super(id, model);
add(new TextField("a"));
add(new TextField("b));
add(new TextField("c"));
}
}
public class Task2FormPanel extends TaskFormPanel<Task2> {
public TaskFormPanel(String id, IModel<Task1> model)
super(id, model);
add(new TextField("x"));
add(new TextField("y));
add(new TextField("z"));
}
}
还有HTML文件:
TaskFormPanel:
TaskFormPanel:
<wicket:panel>
<wicket:child/>
<label>d</label> <input wicket:id="d">
<label>e</label> <input wicket:id="e">
<input type="submit" wicket:id="submit"/>
</wicket:panel>
Task1Panel.html:
Task1Panel.html:
<wicket:extend>
<label>a</label> <input wicket:id="a">
<label>b</label> <input wicket:id="b">
<label>c</label> <input wicket:id="c">
</wicket:extend>
Task2Panel.html:
Task2Panel.html:
<wicket:extend>
<label>x</label> <input wicket:id="x">
<label>y</label> <input wicket:id="y">
<label>z</label> <input wicket:id="z">
</wicket:extend>
注意:如果任务对象包含对线程的引用,请确保使用一些loadabledetachablemodel来包装任务对象,否则将遇到序列化问题.一个单例注册表可以存储您的任务,并可以通过一些随机键将其返回.
Note: make sure you use some loadabledetachablemodel to wrap the task objects in if they contain a reference to a thread otherwise you will run into serialization issues. A singleton registry that stores your tasks and can return them by some random key is enough.
这篇关于Wicket-具有Java继承的可重用面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!