01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.examples.repeater;
18:
19: import org.apache.wicket.AttributeModifier;
20: import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByBorder;
21: import org.apache.wicket.markup.html.basic.Label;
22: import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
23: import org.apache.wicket.markup.repeater.Item;
24: import org.apache.wicket.markup.repeater.data.DataView;
25: import org.apache.wicket.model.AbstractReadOnlyModel;
26:
27: /**
28: * page that demonstrates dataview and sorting
29: *
30: * @author igor
31: *
32: */
33: public class SortingPage extends BasePage {
34: /**
35: * constructor
36: */
37: public SortingPage() {
38: SortableContactDataProvider dp = new SortableContactDataProvider();
39: final DataView dataView = new DataView("sorting", dp) {
40: protected void populateItem(final Item item) {
41: Contact contact = (Contact) item.getModelObject();
42: item.add(new ActionPanel("actions", item.getModel()));
43: item.add(new Label("contactid", String.valueOf(contact
44: .getId())));
45: item
46: .add(new Label("firstname", contact
47: .getFirstName()));
48: item.add(new Label("lastname", contact.getLastName()));
49: item
50: .add(new Label("homephone", contact
51: .getHomePhone()));
52: item
53: .add(new Label("cellphone", contact
54: .getCellPhone()));
55:
56: item.add(new AttributeModifier("class", true,
57: new AbstractReadOnlyModel() {
58: public Object getObject() {
59: return (item.getIndex() % 2 == 1) ? "even"
60: : "odd";
61: }
62: }));
63: }
64: };
65:
66: dataView.setItemsPerPage(8);
67:
68: add(new OrderByBorder("orderByFirstName", "firstName", dp) {
69: protected void onSortChanged() {
70: dataView.setCurrentPage(0);
71: }
72: });
73:
74: add(new OrderByBorder("orderByLastName", "lastName", dp) {
75: protected void onSortChanged() {
76: dataView.setCurrentPage(0);
77: }
78: });
79:
80: add(dataView);
81:
82: add(new PagingNavigator("navigator", dataView));
83: }
84: }
|