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 @Override
103 public String getHtml() {
104 StringBuffer html = new StringBuffer();
105 html.append("<select");
106 html.append(" name=\"" + this.getName() + "\"");
107 html.append(" id=\"" + this.getName() + "\"");
108 if ("true".equalsIgnoreCase(this.getMultiple())) {
109 html.append(" multiple=\"multiple\"");
110 }
111 html.append(this.getHtmlCssClass());
112 html.append(this.getHtmlCssStyles());
113 html.append(this.getHtmlEvents());
114 html.append(">");
115 Iterator it = this.getOptions().iterator();
116 while (it.hasNext()) {
117 SelectOption o = (SelectOption) it.next();
118 if (this.getValueType() == ControlImpl.VALUETYPE_MULTIPLE) {
119 if (this.getValues().size() != 0) {
120 if (this.getValues().contains(o.getValue())) {
121 o.setSelected(true);
122 }
123 else {
124 o.setSelected(false);
125 }
126 }
127 }
128 else {
129 if (StringUtils.isNotEmpty(this.getValue())) {
130 if (this.getValue().equals(o.getValue())) {
131 o.setSelected(true);
132 }
133 else {
134 o.setSelected(false);
135 }
136 }
137 }
138 html.append(o.getHtml());
139 }
140 html.append("</select>");
141 if (this.getSaveInfo()) {
142 html.append(this.getHtmlSaveInfo());
143 }
144 return html.toString();
145 }
146 }