01: /**
02: * Copyright 2006 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.web.demo;
16:
17: import org.araneaframework.example.main.TemplateBaseWidget;
18: import org.araneaframework.uilib.form.FormWidget;
19: import org.araneaframework.uilib.form.control.MultiSelectControl;
20: import org.araneaframework.uilib.form.data.StringListData;
21: import org.araneaframework.uilib.support.DisplayItem;
22:
23: /**
24: * Demonstrates use of multiselect control and markBaseState() isStateChanged() methods.
25: *
26: * @author Taimo Peelo (taimo@araneaframework.org)
27: */
28: public class DemoMultiSelect extends TemplateBaseWidget {
29: private static final long serialVersionUID = 1L;
30: private FormWidget form;
31:
32: protected void init() throws Exception {
33: setViewSelector("demo/demoMultiSelect");
34:
35: MultiSelectControl control = new MultiSelectControl();
36:
37: control.addItem(new DisplayItem("1", "One"));
38: control.addItem(new DisplayItem("2", "Two"));
39: control.addItem(new DisplayItem("3", "Three"));
40: control.addItem(new DisplayItem("4", "Four"));
41:
42: form = new FormWidget();
43: addWidget("form", form);
44: form.addElement("multiselect", "#multi", control,
45: new StringListData(), false);
46:
47: form.markBaseState();
48:
49: StringBuffer sb = new StringBuffer()
50: .append("At the creation, multiselect values are : ");
51: sb.append(form.getValueByFullName("multiselect") != null ? form
52: .getValueByFullName("multiselect").toString() : "null");
53: getMessageCtx().showInfoMessage(sb.toString());
54: }
55:
56: /**
57: * A test action, invoked when button is pressed. It adds the values of
58: * formelements to message context, and they end up at the top of user screen
59: * at the end of the request.
60: */
61: public void handleEventTest() throws Exception {
62: form.convertAndValidate();
63: if (form.isStateChanged())
64: getMessageCtx().showInfoMessage(
65: "State of multiselect control has changed.");
66:
67: getMessageCtx().showInfoMessage(
68: "Multiselect values are "
69: + form.getValueByFullName("multiselect"));
70: form.markBaseState();
71: }
72: }
|