1 /*
2 * $Id: SelectItem.java,v 1.17 2007/04/27 22:00:10 ofung Exp $
3 */
4
5 /*
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
7 *
8 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
9 *
10 * The contents of this file are subject to the terms of either the GNU
11 * General Public License Version 2 only ("GPL") or the Common Development
12 * and Distribution License("CDDL") (collectively, the "License"). You
13 * may not use this file except in compliance with the License. You can obtain
14 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
15 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
16 * language governing permissions and limitations under the License.
17 *
18 * When distributing the software, include this License Header Notice in each
19 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
20 * Sun designates this particular file as subject to the "Classpath" exception
21 * as provided by Sun in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the License
23 * Header, with the fields enclosed by brackets [] replaced by your own
24 * identifying information: "Portions Copyrighted [year]
25 * [name of copyright owner]"
26 *
27 * Contributor(s):
28 *
29 * If you wish your version of this file to be governed by only the CDDL or
30 * only the GPL Version 2, indicate your decision by adding "[Contributor]
31 * elects to include this software in this distribution under the [CDDL or GPL
32 * Version 2] license." If you don't indicate a single choice of license, a
33 * recipient has the option to distribute your version of this file under
34 * either the CDDL, the GPL Version 2 or to extend the choice of license to
35 * its licensees as provided above. However, if you add GPL Version 2 code
36 * and therefore, elected the GPL Version 2 license, then the option applies
37 * only if the new code is made subject to such option by the copyright
38 * holder.
39 */
40
41 package javax.faces.model;
42
43
44 import java.io.Serializable;
45 import javax.faces.component.UISelectMany;
46 import javax.faces.component.UISelectOne;
47
48
49 /**
50 * <p><strong>SelectItem</strong> represents a single <em>item</em> in the
51 * list of supported <em>items</em> associated with a {@link UISelectMany}
52 * or {@link UISelectOne} component.</p>
53 */
54
55 public class SelectItem implements Serializable {
56
57 private static final long serialVersionUID = 876782311414654999L;
58
59
60 // ------------------------------------------------------------ Constructors
61
62
63 /**
64 * <p>Construct a <code>SelectItem</code> with no initialized property
65 * values.</p>
66 */
67 public SelectItem() {
68
69 super();
70
71 }
72
73
74 /**
75 * <p>Construct a <code>SelectItem</code> with the specified value. The
76 * <code>label</code> property will be set to the value (converted to a
77 * String, if necessary), the <code>description</code> property will be
78 * set to <code>null</code>, the <code>disabled</code> property will be set to
79 * <code>false</code>, and the <code>escape</code> property will be set to
80 ( <code>true</code>.</p>
81 *
82 * @param value Value to be delivered to the model if this
83 * item is selected by the user
84 */
85 public SelectItem(Object value) {
86
87 this(value, value == null ? null : value.toString(), null, false, true);
88
89 }
90
91
92 /**
93 * <p>Construct a <code>SelectItem</code> with the specified value and
94 * label. The <code>description</code> property will be set to
95 * <code>null</code>, the <code>disabled</code> property will be
96 * set to <code>false</code>, and the <code>escape</code> property will
97 * be set to <code>true</code>.</p>
98 *
99 * @param value Value to be delivered to the model if this
100 * item is selected by the user
101 * @param label Label to be rendered for this item in the response
102 */
103 public SelectItem(Object value, String label) {
104
105 this(value, label, null, false, true);
106
107 }
108
109
110 /**
111 * <p>Construct a <code>SelectItem</code> instance with the specified
112 * value, label and description. This <code>disabled</code> property
113 * will be set to <code>false</code>, and the <code>escape</code>
114 * property will be set to <code>true</code>.</p>
115 *
116 * @param value Value to be delivered to the model if this
117 * item is selected by the user
118 * @param label Label to be rendered for this item in the response
119 * @param description Description of this item, for use in tools
120 */
121 public SelectItem(Object value, String label, String description) {
122
123 this(value, label, description, false, true);
124
125 }
126
127
128 /**
129 * <p>Construct a <code>SelectItem</code> instance with the specified
130 * property values. The <code>escape</code> property will be set
131 * to <code>true</code>.</p>
132 *
133 * @param value Value to be delivered to the model if this
134 * item is selected by the user
135 * @param label Label to be rendered for this item in the response
136 * @param description Description of this item, for use in tools
137 * @param disabled Flag indicating that this option is disabled
138 */
139 public SelectItem(Object value, String label, String description,
140 boolean disabled) {
141
142 this(value, label, description, disabled, true);
143
144 }
145
146 /**
147 * <p>Construct a <code>SelectItem</code> instance with the specified
148 * property values.</p>
149 *
150 * @param value Value to be delivered to the model if this
151 * item is selected by the user
152 * @param label Label to be rendered for this item in the response
153 * @param description Description of this item, for use in tools
154 * @param disabled Flag indicating that this option is disabled
155 * @param escape Flag indicating that the text of this option should be
156 * escaped when rendered.
157 * @since 1.2
158 */
159 public SelectItem(Object value, String label, String description,
160 boolean disabled, boolean escape) {
161
162 super();
163 setValue(value);
164 setLabel(label);
165 setDescription(description);
166 setDisabled(disabled);
167 setEscape(escape);
168
169 }
170
171
172
173
174 // ------------------------------------------------------ Instance Variables
175
176
177 private String description = null;
178 private boolean disabled = false;
179 private String label = null;
180 @SuppressWarnings({"NonSerializableFieldInSerializableClass"})
181 private Object value = null;
182
183
184 // -------------------------------------------------------------- Properties
185
186
187 /**
188 * <p>Return a description of this item, for use in development tools.
189 */
190 public String getDescription() {
191
192 return (this.description);
193
194 }
195
196
197 /**
198 * <p>Set the description of this item, for use in development tools.</p>
199 *
200 * @param description The new description
201 */
202 public void setDescription(String description) {
203
204 this.description = description;
205
206 }
207
208
209 /**
210 * <p>Return the disabled flag for this item, which should modify the
211 * rendered output to make this item unavailable for selection by the user
212 * if set to <code>true</code>.</p>
213 */
214 public boolean isDisabled() {
215
216 return (this.disabled);
217
218 }
219
220
221 /**
222 * <p>Set the disabled flag for this item, which should modify the
223 * rendered output to make this item unavailable for selection by the user
224 * if set to <code>true</code>.</p>
225 *
226 * @param disabled The new disabled flag
227 */
228 public void setDisabled(boolean disabled) {
229
230 this.disabled = disabled;
231
232 }
233
234
235 /**
236 * <p>Return the label of this item, to be rendered visibly for the user.
237 */
238 public String getLabel() {
239
240 return (this.label);
241
242 }
243
244
245 /**
246 * <p>Set the label of this item, to be rendered visibly for the user.
247 *
248 * @param label The new label
249 */
250 public void setLabel(String label) {
251
252 this.label = label;
253
254 }
255
256
257 /**
258 * <p>Return the value of this item, to be delivered to the model
259 * if this item is selected by the user.
260 */
261 public Object getValue() {
262
263 return (this.value);
264
265 }
266
267
268 /**
269 * <p>Set the value of this item, to be delivered to the model
270 * if this item is selected by this user.
271 *
272 * @param value The new value
273 *
274 */
275 public void setValue(Object value) {
276
277 this.value = value;
278
279 }
280
281 /**
282 * Holds value of property escape.
283 */
284 private boolean escape;
285
286 /**
287 * Getter for property escape.
288 * @return Value of property escape.
289 */
290 public boolean isEscape() {
291 return this.escape;
292 }
293
294 /**
295 * Setter for property escape.
296 * @param escape New value of property escape.
297 */
298 public void setEscape(boolean escape) {
299 this.escape = escape;
300 }
301
302
303 }