步驟一.建置一個PageableListPageExamples.html
<html>
<body>
<form wicket:id="form" action="">
<span wicket:id="navigator">這裏顯示分頁操作</span>
<table width="240" border="1" bordercolor="orange">
<tr>
<th>選擇</th>
<th>序號</th>
<th>書名</th>
<th>作者</th>
<th>操作</th>
</tr>
<tr wicket:id="books">
<td>
<input type="checkbox" wicket:id="selected"/>
</td>
<td wicket:id="id">id</td>
<td wicket:id="title">title</td>
<td wicket:id="author">author</td>
<td>
<a wicket:id="edit">edit</a>
</td>
</tr>
</table>
<input type="submit"/>
</form>
</body>
</html>
步驟二.建置一個Book.java類別
package wicket.examples.html.body.form.list;
import java.io.Serializable;
public class Book implements Serializable {
private int id;
//編號
private String title;
//書名
private String author;
//作者
private boolean selected;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public void setTitle(String title) {
this.title = title;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public boolean isSelected() {
return selected;
}
public boolean getSelected() {
return selected;
}
public String getTitle() {
return title;
}
}
步驟三.建置PageableListPageExamples.java
package wicket.examples.html.body.form.list;
import java.util.ArrayList;
import java.util.List;
import wicket.markup.html.WebPage;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.CheckBox;
import wicket.markup.html.form.Form;
import wicket.markup.html.link.Link;
import wicket.markup.html.list.ListItem;
import wicket.markup.html.list.PageableListView;
import wicket.markup.html.navigation.paging.PagingNavigator;
import wicket.model.PropertyModel;
public class PageableListPageExamples extends WebPage {
private static List books = new ArrayList();
static {
for (int i = 1; i < 100; i++) {
Book book = new Book();
book.setId(i);
book.setAuthor("author" + i);
book.setTitle("title" + i);
books.add(book);
}
}
public PageableListPageExamples() {
super();
Form cForm = new Form("form");
final PageableListView listView = new PageableListView("books", books, 10) {
protected void populateItem(ListItem item) {
final Book book = (Book) item.getModelObject();
item.add(new CheckBox("selected", new PropertyModel(book, "selected")));
item.add(new Label("id", Integer.toString(book.getId())));
item.add(new Label("title", book.getTitle()));
item.add(new Label("author", book.getAuthor()));
item.add(new Link("edit") {
public void onClick() {
//轉向編輯頁面
}
});
}
};
cForm.add(listView);
cForm.add(new PagingNavigator("navigator", listView));
this.add(cForm);
}
}
步驟四..修改Examples.html & Examples.java
...
<tr>
<td><a wicket:id="Examples19">show PageableListPageExamplesPage</a></td>
</tr>
...
...
add(new PageLink("Examples19",PageableListPageExamples.class));
...
沒有留言:
張貼留言