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