Dynamically add components to ListView in Wicket

前端 未结 1 475
小蘑菇
小蘑菇 2021-02-06 15:00

I want to make a form with \"Add\" button. After pressing \"Add\" button new panel adds to the wicket ListView element. How do I do that? I want to be able add unlimited number

相关标签:
1条回答
  • 2021-02-06 15:03

    I suppose you already display a list of elements in a ListView? You than simply add new elements to the list that backup your ListView. Consider that the ListView will not refresh the items if you pass in the List in the constructor.

    So, instead of

    List<Person> personList = new LinkedList<Person>();
    ListView<Person> personView = new ListView<Person("listview", personList);
    

    you should use a Model that wraps the List:

    ListView<Person> personView = new ListView<Person("listview"
                   , new PropertyModel<List<Person>>(this, "personList");
    

    along with a getPersonList() accessor in this.

    You can have a look at Legup and generate the Wicket, Spring, JPA archetype. In the code you will find a EventPage that does this.

    0 讨论(0)
提交回复
热议问题