comparison src/main/java/javax/faces/model/SelectItem.java @ 1:2e911857a759

(none)
author jurzua
date Wed, 29 Oct 2014 14:00:28 +0000
parents
children
comparison
equal deleted inserted replaced
0:74df02964906 1:2e911857a759
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can
10 * obtain a copy of the License at
11 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12 * or packager/legal/LICENSE.txt. See the License for the specific
13 * language governing permissions and limitations under the License.
14 *
15 * When distributing the software, include this License Header Notice in each
16 * file and include the License file at packager/legal/LICENSE.txt.
17 *
18 * GPL Classpath Exception:
19 * Oracle designates this particular file as subject to the "Classpath"
20 * exception as provided by Oracle in the GPL Version 2 section of the License
21 * file that accompanied this code.
22 *
23 * Modifications:
24 * If applicable, add the following below the License Header, with the fields
25 * enclosed by brackets [] replaced by your own identifying information:
26 * "Portions Copyright [year] [name of copyright owner]"
27 *
28 * Contributor(s):
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 class="changed_modified_2_0
51 * changed_modified_2_0_rev_a">SelectItem</strong> represents a single
52 * <em>item</em> in the list of supported <em>items</em> associated with
53 * a {@link UISelectMany} or {@link UISelectOne} component.</p>
54 */
55
56 public class SelectItem implements Serializable {
57
58 private static final long serialVersionUID = 876782311414654999L;
59
60
61 // ------------------------------------------------------------ Constructors
62
63
64 /**
65 * <p>Construct a <code>SelectItem</code> with no initialized property
66 * values.</p>
67 */
68 public SelectItem() {
69
70 super();
71
72 }
73
74
75 /**
76 * <p>Construct a <code>SelectItem</code> with the specified value. The
77 * <code>label</code> property will be set to the value (converted to a
78 * String, if necessary), the <code>description</code> property will be
79 * set to <code>null</code>, the <code>disabled</code> property will be set to
80 * <code>false</code>, and the <code>escape</code> property will be set to
81 ( <code>true</code>.</p>
82 *
83 * @param value Value to be delivered to the model if this
84 * item is selected by the user
85 */
86 public SelectItem(Object value) {
87
88 this(value, value == null ? null : value.toString(), null, false, true, false);
89
90 }
91
92
93 /**
94 * <p>Construct a <code>SelectItem</code> with the specified value and
95 * label. The <code>description</code> property will be set to
96 * <code>null</code>, the <code>disabled</code> property will be
97 * set to <code>false</code>, and the <code>escape</code> property will
98 * be set to <code>true</code>.</p>
99 *
100 * @param value Value to be delivered to the model if this
101 * item is selected by the user
102 * @param label Label to be rendered for this item in the response
103 */
104 public SelectItem(Object value, String label) {
105
106 this(value, label, null, false, true, false);
107
108 }
109
110
111 /**
112 * <p>Construct a <code>SelectItem</code> instance with the specified
113 * value, label and description. This <code>disabled</code> property
114 * will be set to <code>false</code>, and the <code>escape</code>
115 * property will be set to <code>true</code>.</p>
116 *
117 * @param value Value to be delivered to the model if this
118 * item is selected by the user
119 * @param label Label to be rendered for this item in the response
120 * @param description Description of this item, for use in tools
121 */
122 public SelectItem(Object value, String label, String description) {
123
124 this(value, label, description, false, true, false);
125
126 }
127
128
129 /**
130 * <p>Construct a <code>SelectItem</code> instance with the specified
131 * property values. The <code>escape</code> property will be set
132 * to <code>true</code>.</p>
133 *
134 * @param value Value to be delivered to the model if this
135 * item is selected by the user
136 * @param label Label to be rendered for this item in the response
137 * @param description Description of this item, for use in tools
138 * @param disabled Flag indicating that this option is disabled
139 */
140 public SelectItem(Object value, String label, String description,
141 boolean disabled) {
142
143 this(value, label, description, disabled, true, false);
144
145 }
146
147 /**
148 * <p>Construct a <code>SelectItem</code> instance with the specified
149 * property values.</p>
150 *
151 * @param value Value to be delivered to the model if this
152 * item is selected by the user
153 * @param label Label to be rendered for this item in the response
154 * @param description Description of this item, for use in tools
155 * @param disabled Flag indicating that this option is disabled
156 * @param escape Flag indicating that the text of this option should be
157 * escaped when rendered.
158 * @since 1.2
159 */
160 public SelectItem(Object value, String label, String description,
161 boolean disabled, boolean escape) {
162
163 this(value, label, description, disabled, escape, false);
164
165 }
166
167
168 /**
169 * <p>Construct a <code>SelectItem</code> instance with the specified
170 * property values.</p>
171 *
172 * @param value Value to be delivered to the model if this
173 * item is selected by the user
174 * @param label Label to be rendered for this item in the response
175 * @param description Description of this item, for use in tools
176 * @param disabled Flag indicating that this option is disabled
177 * @param escape Flag indicating that the text of this option should be
178 * escaped when rendered.
179 * @param noSelectionOption Flag indicating that the current option is a "no selection" option
180 * @since 1.2
181 */
182 public SelectItem(Object value, String label, String description,
183 boolean disabled, boolean escape, boolean noSelectionOption) {
184
185 super();
186 setValue(value);
187 setLabel(label);
188 setDescription(description);
189 setDisabled(disabled);
190 setEscape(escape);
191 setNoSelectionOption(noSelectionOption);
192
193 }
194
195
196
197
198 // ------------------------------------------------------ Instance Variables
199
200
201 private String description = null;
202 private boolean disabled = false;
203 private String label = null;
204 //@author jurzua
205 private String style = null;
206 @SuppressWarnings({"NonSerializableFieldInSerializableClass"})
207 private Object value = null;
208
209
210 // -------------------------------------------------------------- Properties
211
212
213 /**
214 * <p>Return a description of this item, for use in development tools.
215 */
216 public String getDescription() {
217
218 return (this.description);
219
220 }
221
222
223 /**
224 * <p>Set the description of this item, for use in development tools.</p>
225 *
226 * @param description The new description
227 */
228 public void setDescription(String description) {
229
230 this.description = description;
231
232 }
233
234
235 /**
236 * <p>Return the disabled flag for this item, which should modify the
237 * rendered output to make this item unavailable for selection by the user
238 * if set to <code>true</code>.</p>
239 */
240 public boolean isDisabled() {
241
242 return (this.disabled);
243
244 }
245
246
247 /**
248 * <p>Set the disabled flag for this item, which should modify the
249 * rendered output to make this item unavailable for selection by the user
250 * if set to <code>true</code>.</p>
251 *
252 * @param disabled The new disabled flag
253 */
254 public void setDisabled(boolean disabled) {
255
256 this.disabled = disabled;
257
258 }
259
260
261 /**
262 * <p>Return the label of this item, to be rendered visibly for the user.
263 */
264 public String getLabel() {
265
266 return (this.label);
267
268 }
269
270
271 /**
272 * <p>Set the label of this item, to be rendered visibly for the user.
273 *
274 * @param label The new label
275 */
276 public void setLabel(String label) {
277
278 this.label = label;
279
280 }
281
282
283 /**
284 * <p>Return the value of this item, to be delivered to the model
285 * if this item is selected by the user.
286 */
287 public Object getValue() {
288
289 return (this.value);
290
291 }
292
293
294 /**
295 * <p>Set the value of this item, to be delivered to the model
296 * if this item is selected by this user.
297 *
298 * @param value The new value
299 *
300 */
301 public void setValue(Object value) {
302
303 this.value = value;
304
305 }
306
307 private boolean escape;
308
309 /**
310 * <p class="changed_added_2_0_rev_a">If and only if this returns
311 * <code>true</code>, the code that renders this select item must
312 * escape the label using escaping syntax appropriate to the content
313 * type being rendered. </p>
314 *
315 * @since 2.0
316 */
317 public boolean isEscape() {
318 return this.escape;
319 }
320
321 /**
322 * <p class="changed_added_2_0_rev_a">Set the value of the escape
323 * property. See {@link #isEscape}.</p>
324 *
325 * @since 2.0
326 */
327 public void setEscape(boolean escape) {
328 this.escape = escape;
329 }
330
331 private boolean noSelectionOption = false;
332
333 /** <p class="changed_added_2_0">Return the value of the
334 * <code>noSelectionOption</code> property. If the value of this
335 * property is <code>true</code>, the system interprets the option
336 * represented by this <code>SelectItem</code> instance as
337 * representing a "no selection" option. See {@link
338 * UISelectOne#validateValue} and {@link UISelectMany#validateValue}
339 * for usage.</p>
340 *
341 * @since 2.0
342 */
343
344 public boolean isNoSelectionOption() {
345 return noSelectionOption;
346 }
347
348 /**
349 * <p class="changed_added_2_0">Set the value of the
350 * <code>noSelectionOption</code> property.</p>
351 *
352 * @since 2.0
353 */
354
355 public void setNoSelectionOption(boolean noSelectionOption) {
356 this.noSelectionOption = noSelectionOption;
357 }
358
359 /**
360 * @author jurzua
361 */
362 public void setStyle(String style){
363 this.style = style;
364 }
365
366 /**
367 * @author jurzua
368 */
369 public String getStyle(){
370 return (this.style);
371 }
372
373 }