Can anyone point me in the right direction here. Im wanting to have say 2 textfields initially then the user will be able to click 'add' button and another 2 textfields will be displayed (this needs to be dynamic as the user could click once or a 100 times for example)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Since it's wicket, it should be Java... I would retag this but my account is to new for that...
Put your initial Textfields models into a single wrapper-object and add this to a list (thus containing only one element) and display this list in a ListView. In the onClick Event of your Button, add another of these wrapper-objects to your list and refresh the ListView.
Something like
public class TwoTextFields {
private IModel textFieldOne;
private IModel textFieldTwo;
[... constructor, getters setters here ...]
and
public class MyPanel extends Panel {
private List<TwoTextFields> list = new ArrayList<TwoTextFields>();
public MyPanel(String id) {
super(id);
add( New ListView<TwoTextFields>("list", list) {
@Override
protected populateItem(Item<TwoTextFields> item) {
add( new TextField("fieldOne", new PropertyModel(item, "textFieldOne");
add( new TextField("fieldTwo", new PropertyModel(item, "textFieldTwo");
}
});
add( new Button("button) {
@Override
protected void onClick() {
list.add(new TwoTextFields());
}
});
}
I don't know if this compiles... It's just to give you the idea, didn't want to fire up eclipse for that...