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 java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22:
23: import org.apache.wicket.AttributeModifier;
24: import org.apache.wicket.markup.html.basic.Label;
25: import org.apache.wicket.markup.html.link.Link;
26: import org.apache.wicket.markup.repeater.Item;
27: import org.apache.wicket.markup.repeater.RefreshingView;
28: import org.apache.wicket.model.AbstractReadOnlyModel;
29:
30: /**
31: * page that demonstrates a RefreshingView
32: *
33: * @see RefreshingView
34: *
35: * @author igor
36: */
37: public class RefreshingPage extends BasePage {
38: /**
39: * Constructor
40: */
41: public RefreshingPage() {
42: final List contacts = new ArrayList(10);
43:
44: // populate list of contacts to be displayed
45: ContactDataProvider dp = new ContactDataProvider();
46: Iterator it = dp.iterator(0, 10);
47: while (it.hasNext()) {
48: contacts.add(dp.model(it.next()));
49: }
50:
51: // create the refreshing view
52: RefreshingView view = new RefreshingView("view") {
53: /**
54: * Return an iterator over models for items in the view
55: */
56: protected Iterator getItemModels() {
57: return contacts.iterator();
58: }
59:
60: protected void populateItem(final Item item) {
61: Contact contact = (Contact) item.getModelObject();
62: item.add(new Label("itemid", item.getId()));
63: item.add(new ActionPanel("actions", item.getModel()));
64: item.add(new Label("contactid", String.valueOf(contact
65: .getId())));
66: item
67: .add(new Label("firstname", contact
68: .getFirstName()));
69: item.add(new Label("lastname", contact.getLastName()));
70: item
71: .add(new Label("homephone", contact
72: .getHomePhone()));
73: item
74: .add(new Label("cellphone", contact
75: .getCellPhone()));
76:
77: item.add(new AttributeModifier("class", true,
78: new AbstractReadOnlyModel() {
79: public Object getObject() {
80: return (item.getIndex() % 2 == 1) ? "even"
81: : "odd";
82: }
83: }));
84: }
85: };
86:
87: add(view);
88:
89: add(new Link("refreshLink") {
90: public void onClick() {
91: // noop
92: }
93: });
94: }
95: }
|