Refactor Wicket examples

This commit is contained in:
Grzegorz Piwowarek 2016-10-10 06:46:31 +02:00
parent 423dc63cdd
commit 687b7e0044
2 changed files with 14 additions and 22 deletions

View File

@ -1,10 +1,5 @@
package com.baeldung.wicket.examples.cafeaddress;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebPage;
@ -13,29 +8,29 @@ import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class CafeAddress extends WebPage {
private static final long serialVersionUID = 1L;
String selectedCafe;
Address address;
Map<String, Address> cafeNamesAndAddresses = new HashMap<>();
private String selectedCafe;
private Address address;
private Map<String, Address> cafeNamesAndAddresses = new HashMap<>();
public CafeAddress(final PageParameters parameters) {
super(parameters);
initCafes();
ArrayList<String> cafeNames = new ArrayList<>(this.cafeNamesAndAddresses.keySet());
this.selectedCafe = cafeNames.get(0);
this.address = new Address(this.cafeNamesAndAddresses.get(this.selectedCafe).getAddress());
ArrayList<String> cafeNames = new ArrayList<>(cafeNamesAndAddresses.keySet());
selectedCafe = cafeNames.get(0);
address = new Address(cafeNamesAndAddresses.get(selectedCafe).getAddress());
final Label addressLabel = new Label("address", new PropertyModel<String>(this.address, "address"));
addressLabel.setOutputMarkupId(true);
final DropDownChoice<String> cafeDropdown = new DropDownChoice<>("cafes", new PropertyModel<String>(this, "selectedCafe"), cafeNames);
final DropDownChoice<String> cafeDropdown = new DropDownChoice<>("cafes", new PropertyModel<>(this, "selectedCafe"), cafeNames);
cafeDropdown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
String name = (String) cafeDropdown.getDefaultModel().getObject();
@ -61,11 +56,11 @@ public class CafeAddress extends WebPage {
this.sAddress = address;
}
public String getAddress() {
String getAddress() {
return this.sAddress;
}
public void setAddress(String address) {
void setAddress(String address) {
this.sAddress = address;
}
}

View File

@ -4,9 +4,6 @@ import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
public class HelloWorld extends WebPage {
private static final long serialVersionUID = 1L;
public HelloWorld() {
add(new Label("hello", "Hello World!"));
}