01: /**
02: * Copyright 2007 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.example.main.release.demos;
16:
17: import java.text.SimpleDateFormat;
18: import java.util.Date;
19: import java.util.Random;
20: import org.araneaframework.InputData;
21: import org.araneaframework.OutputData;
22: import org.araneaframework.core.StandardActionListener;
23: import org.araneaframework.example.main.TemplateBaseWidget;
24: import org.araneaframework.http.HttpOutputData;
25: import org.araneaframework.uilib.util.MessageUtil;
26:
27: /**
28: * @author Taimo Peelo (taimo@araneaframework.org)
29: */
30: public class DemoActionPollWidget extends TemplateBaseWidget {
31: protected void init() throws Exception {
32: setViewSelector("release/demos/demoActionPoll");
33: addActionListener("pollrequest", new TaskPollingListener());
34: }
35:
36: public class TaskPollingListener extends StandardActionListener {
37: private Random rn = new Random();
38: int lastRandom = 0;
39:
40: public void processAction(Object actionId, String actionParam,
41: InputData input, OutputData output) throws Exception {
42: int random = rn.nextInt(100);
43: lastRandom = random;
44:
45: HttpOutputData httpOutput = (HttpOutputData) output;
46: String s = "NOTHING";
47:
48: if (rn.nextInt(3) == 1) {
49: s = MessageUtil.localizeAndFormat("poll.taskmsg",
50: new Object[] {
51: String.valueOf(random),
52: new SimpleDateFormat("HH:mm.ss")
53: .format(new Date()) },
54: getEnvironment())
55: + "<br/>";
56: }
57:
58: httpOutput.setContentType("text/xml");
59: httpOutput.getWriter().write(s);
60: }
61: }
62: }
|