1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.control;
35
36 import info.magnolia.cms.core.Content;
37
38 import java.util.ArrayList;
39 import java.util.Iterator;
40 import java.util.List;
41
42 import org.apache.commons.lang.StringUtils;
43
44
45
46
47
48
49 public class Select extends ControlImpl {
50
51 private List options = new ArrayList();
52
53 private String multiple = "false";
54
55 public Select() {
56 }
57
58 public Select(String name, String value) {
59 super(name, value);
60 }
61
62 public Select(String name, List values) {
63 super(name, values);
64 }
65
66 public Select(String name, Content websiteNode) {
67 super(name, websiteNode);
68 }
69
70 public void setOptions(List l) {
71 this.options = l;
72 }
73
74 public void setOptions(SelectOption option) {
75 this.getOptions().add(option);
76 }
77
78 public void setOptions(String label, String value) {
79 this.getOptions().add(new SelectOption(label, value));
80 }
81
82 public List getOptions() {
83 return this.options;
84 }
85
86
87
88
89
90 public void setMultiple(String multiple) {
91 this.multiple = multiple;
92 }
93
94
95
96
97
98 public String getMultiple() {
99 return multiple;
100 }
101
102 public String getHtml() {
103 StringBuffer html = new StringBuffer();
104 html.append("<select");
105 html.append(" name=\"" + this.getName() + "\"");
106 html.append(" id=\"" + this.getName() + "\"");
107 if ("true".equalsIgnoreCase(this.getMultiple())) {
108 html.append(" multiple=\"multiple\"");
109 }
110 html.append(this.getHtmlCssClass());
111 html.append(this.getHtmlCssStyles());
112 html.append(this.getHtmlEvents());
113 html.append(">");
114 Iterator it = this.getOptions().iterator();
115 while (it.hasNext()) {
116 SelectOption o = (SelectOption) it.next();
117 if (this.getValueType() == ControlImpl.VALUETYPE_MULTIPLE) {
118 if (this.getValues().size() != 0) {
119 if (this.getValues().contains(o.getValue())) {
120 o.setSelected(true);
121 }
122 else {
123 o.setSelected(false);
124 }
125 }
126 }
127 else {
128 if (StringUtils.isNotEmpty(this.getValue())) {
129 if (this.getValue().equals(o.getValue())) {
130 o.setSelected(true);
131 }
132 else {
133 o.setSelected(false);
134 }
135 }
136 }
137 html.append(o.getHtml());
138 }
139 html.append("</select>");
140 if (this.getSaveInfo()) {
141 html.append(this.getHtmlSaveInfo());
142 }
143 return html.toString();
144 }
145 }