Hi there,
I'm new to wicket and got a problem, I searched google and the mailing list for
2 days now but can't find what I'm searching for, here is an reduced example of
what I'm trying to do.
This is very simplified and not the domain I'm working in, this is just used for
ease. I'm using wicket:6:16:0.
The Example in short: I have a person with multiple addresses. For the person
there is a form with a textfield for the name. Under that textfield is an ajax
link to add a panel containing an form for an address. The background-model is a
class person with a name string and a list of addresses and an address class
with a street/city string.
My problem now is how i can dynamically add addresses to that person.
Models:
===Person.java===
...
private String name;
private List<Address> addresses;
//getter/setter
...
===/Person.java===
===Address.java===
...
private String street;
private String city;
...
//getter/setter
....
===/Address.java===
===AddressPanel.java===
...
public Address(String id, IModel<Address> model) {
super(id, model);
SetDefaultModel(model);
Form<?> form = new Form<Void>("form");
TextField<String> street = new TextField<String>("street");
form.add(street);
TextField<String> city = new TextField<String>("city");
form.add(city);
add(city);
===/AddressPanel.java===
===AddressPanel.html===
<htmlstuff...>
<wicket:panel>
<form wicket:id="form">
<input type="text" wicket:id="street"/>
<input type="text" wicket:id="city"/>
</form>
</wicket:panel>
</htmlstuff...>
===/AddressPanel.html===
===PersonPage.html===
<htmlstuff...>
<form wicket:id="form">
<input type="text" wicket:id="name"/>
<div wicket:id="addresses"/>
<a href="#" wicket:id="addAddress">add address</a>
</form>
</htmlstuff...>
===/PersonPage.html===
===PersonPage.java===
public class PersonPage extends WebPage {
Person person;
public PersonPage() {
person = new Person();
setDefaultModel(new CompoundPropertyModel<Person>(person);
Form<?> form = new Form<Void>("form");
TextField<String> name = new TextField<String>("name");
form.add(name);
add(form);
//And here the troube begins, do I use an ListView? If so for AddressPanel
I think, but which model do I give to it?
AjaxSubmitLink addLink = new AjaxSubmitLink("addAddress", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
// Do I now create a new Address or AddressPanel? If I create an
AddressPanel which Model do I use? How is the Address appended to the addresses
list in Person?
many thanks in advance
Gunnar
I'm new to wicket and got a problem, I searched google and the mailing list for
2 days now but can't find what I'm searching for, here is an reduced example of
what I'm trying to do.
This is very simplified and not the domain I'm working in, this is just used for
ease. I'm using wicket:6:16:0.
The Example in short: I have a person with multiple addresses. For the person
there is a form with a textfield for the name. Under that textfield is an ajax
link to add a panel containing an form for an address. The background-model is a
class person with a name string and a list of addresses and an address class
with a street/city string.
My problem now is how i can dynamically add addresses to that person.
Models:
===Person.java===
...
private String name;
private List<Address> addresses;
//getter/setter
...
===/Person.java===
===Address.java===
...
private String street;
private String city;
...
//getter/setter
....
===/Address.java===
===AddressPanel.java===
...
public Address(String id, IModel<Address> model) {
super(id, model);
SetDefaultModel(model);
Form<?> form = new Form<Void>("form");
TextField<String> street = new TextField<String>("street");
form.add(street);
TextField<String> city = new TextField<String>("city");
form.add(city);
add(city);
===/AddressPanel.java===
===AddressPanel.html===
<htmlstuff...>
<wicket:panel>
<form wicket:id="form">
<input type="text" wicket:id="street"/>
<input type="text" wicket:id="city"/>
</form>
</wicket:panel>
</htmlstuff...>
===/AddressPanel.html===
===PersonPage.html===
<htmlstuff...>
<form wicket:id="form">
<input type="text" wicket:id="name"/>
<div wicket:id="addresses"/>
<a href="#" wicket:id="addAddress">add address</a>
</form>
</htmlstuff...>
===/PersonPage.html===
===PersonPage.java===
public class PersonPage extends WebPage {
Person person;
public PersonPage() {
person = new Person();
setDefaultModel(new CompoundPropertyModel<Person>(person);
Form<?> form = new Form<Void>("form");
TextField<String> name = new TextField<String>("name");
form.add(name);
add(form);
//And here the troube begins, do I use an ListView? If so for AddressPanel
I think, but which model do I give to it?
AjaxSubmitLink addLink = new AjaxSubmitLink("addAddress", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
// Do I now create a new Address or AddressPanel? If I create an
AddressPanel which Model do I use? How is the Address appended to the addresses
list in Person?
many thanks in advance
Gunnar