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.ajax.builtin;
18:
19: import java.util.TimeZone;
20:
21: import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
22: import org.apache.wicket.ajax.AjaxRequestTarget;
23: import org.apache.wicket.util.time.Duration;
24:
25: /**
26: * A world clock example page. Demonstrates timer behavior as well as multiple
27: * component update.
28: *
29: * @author Igor Vaynberg (ivaynberg)
30: */
31: public class WorldClockPage extends BasePage {
32: /**
33: * Constructor
34: */
35: public WorldClockPage() {
36: // create clock components for different timezones
37: final Clock la = new Clock("la", TimeZone
38: .getTimeZone("America/Los_Angeles"));
39: final Clock ny = new Clock("ny", TimeZone
40: .getTimeZone("America/New_York"));
41: final Clock moscow = new Clock("moscow", TimeZone
42: .getTimeZone("Europe/Moscow"));
43: final Clock prague = new Clock("prague", TimeZone
44: .getTimeZone("Europe/Prague"));
45: final Clock london = new Clock("london", TimeZone
46: .getTimeZone("Europe/London"));
47:
48: // make components print out id attrs so they can be updated via ajax
49: la.setOutputMarkupId(true);
50: ny.setOutputMarkupId(true);
51: moscow.setOutputMarkupId(true);
52: prague.setOutputMarkupId(true);
53: london.setOutputMarkupId(true);
54:
55: // add the components to the container and add a markup id setter to
56: // each component.
57: add(la);
58: add(ny);
59: add(moscow);
60: add(prague);
61: add(london);
62:
63: // add the timer behavior to the page and make it update all
64: // other components as well
65: add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
66: /**
67: * @see org.apache.wicket.ajax.AbstractAjaxTimerBehavior#onTimer(org.apache.wicket.ajax.AjaxRequestTarget)
68: */
69: protected void onTimer(AjaxRequestTarget target) {
70: target.addComponent(la);
71: target.addComponent(ny);
72: target.addComponent(moscow);
73: target.addComponent(prague);
74: target.addComponent(london);
75: }
76: });
77: }
78: }
|