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.markup.html.basic.Label;
21: import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
22: import org.apache.wicket.markup.repeater.Item;
23: import org.apache.wicket.markup.repeater.data.DataView;
24: import org.apache.wicket.model.AbstractReadOnlyModel;
25:
26: /**
27: * Page that demonstrates a paging dataview
28: *
29: * @see org.apache.wicket.markup.html.navigation.paging.PagingNavigator
30: * @author igor
31: *
32: */
33: public class PagingPage extends BasePage {
34: /**
35: * constructor
36: */
37: public PagingPage() {
38: DataView dataView = new DataView("pageable",
39: new ContactDataProvider()) {
40:
41: protected void populateItem(final Item item) {
42: Contact contact = (Contact) item.getModelObject();
43: item.add(new ActionPanel("actions", item.getModel()));
44: item.add(new Label("contactid", String.valueOf(contact
45: .getId())));
46: item
47: .add(new Label("firstname", contact
48: .getFirstName()));
49: item.add(new Label("lastname", contact.getLastName()));
50: item
51: .add(new Label("homephone", contact
52: .getHomePhone()));
53: item
54: .add(new Label("cellphone", contact
55: .getCellPhone()));
56:
57: item.add(new AttributeModifier("class", true,
58: new AbstractReadOnlyModel() {
59: public Object getObject() {
60: return (item.getIndex() % 2 == 1) ? "even"
61: : "odd";
62: }
63: }));
64: }
65: };
66:
67: dataView.setItemsPerPage(8);
68: add(dataView);
69:
70: add(new PagingNavigator("navigator", dataView));
71: }
72: }
|