wicket pallete初识
wicket 之Pallete
使用Pallete实现下面效果:
Html代码 MyPallete.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form wicket:id="form">
<span wicket:id="palette">面板区域</span>
</form>
</body>
</html>
java 代码:
Book.java
mport java.io.Serializable;
//实现比较器Comparable
public class Book implements Serializable,Comparable<Book> {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
private String id;
private String name;
public Book(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int compareTo(Book o) {
return id.compareToIgnoreCase(o.getId());
}
}
MyPallete.java
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.model.Model;
public class MyPalette extends WebPage {
public MyPalette() {
List<Book> list=Arrays.asList(new Book("001","语文"),new Book("002","数学"),new Book("003","英语"),new Book("004","物理"));
//初始化右侧
List<Book> init=Arrays.asList(new Book("001","语文"),new Book("002","数学"));
Form form =new Form("form");
add(form);
IChoiceRenderer<Book> renderer=new ChoiceRenderer<Book>("name", "id");
/*
new IChoiceRenderer<Book>() {
@Override
public Object getDisplayValue(Book object) {
return object.getName();
}
@Override
public String getIdValue(Book object, int index) {
return object.getId();
}
};*/
final Palette<Book> palette=new Palette<Book>("palette", new Model((Serializable) init), new Model((Serializable) list), renderer, 10, true);
form.add( palette );
}
}