001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.el.MethodBinding;
047: import javax.faces.el.ValueBinding;
048:
049: /**
050: * <h4>About this tag</h4>
051: *
052: * <p>This tag renders a listbox. Use the <code>selected</code>
053: * attribute to associate the component with a model object that
054: * represents the current choice, by setting the value to an EL
055: * expression that corresponds to a property of a
056: * managed bean.</p>
057: *
058: * <h4>Configuring the listbox tag</h4>
059: *
060: * <p>Use the <code>multiple</code> attribute to specify whether the
061: * component accepts multiple selections. By default this is set to
062: * false. If multiple selections are allowed, the model object
063: * property must be either an array of primitives, an array of
064: * objects, or a (subclass of) <code>java.util.List</code>.</p>
065: *
066: * <p>Use the <code>items</code> attribute to specify the options
067: * from which the web application user can choose. The value must be
068: * an EL expression that identifies an array, a
069: * <code>java.util.Collection</code> or a <code>java.util.Map</code>
070: * of <code>com.sun.rave.web.ui.Option</code>. </p>
071: *
072: * <p>The first time the component is rendered, the options which
073: * correspond to the value of the <code>selected</code> model object
074: * property is marked as selected, using the <code>equals</code>
075: * method on the model object. </p>
076: *
077: * <p>The number of list items simultaneously shown can be specified
078: * using the <code>rows</code> attribute, and the component will be
079: * rendered using a monospaced font if the <code>useMonospace</code>
080: * attribute is set to true.</p>
081: *
082: * <p>To optionally specify a label for the component, use the
083: * <code>label</code> attribute, or specify a label facet.</p>
084: *
085: * <h4>Facets</h4>
086: *
087: * <ul>
088: * <li><code>label</code>: use this facet to specify a custom
089: * component for the label.</li>
090: * </ul>
091: *
092: * <h4>Client-side JavaScript functions</h4>
093: *
094: * <ul>
095: * <li><code>listbox_setDisabled(<id>, <disabled>)</code>: use
096: * this function to enable/disable the listbox. <code><id></code>
097: * must be the generated id of the component. Set
098: * <code><disabled></code> to true to disable the component,
099: * false to enable it. </li>
100: * <li><code>listbox_changed(<id>)</code>: this
101: * function is automatically invoked by the listbox's
102: * <code>onchange</code> handler. <code><id></code>
103: * must be the generated id of the component.</li>
104: * </ul>
105: *
106: * <h4>Examples</h4>
107: * <pre>
108: *
109: * <ui:listbox selected="#{flightSearch.leaveAirport}"
110: * items="#{dataBean.airports}"
111: * rows="6"
112: * id="leaveAirport"
113: * toolTip="#{msgs.chooseAirport}"
114: * label="#{msgs.chooseDepartureAirport)" />
115: *
116: * <ui:listbox selected="#{flightSearch.leaveAirport}"
117: * items="#{dataBean.airports}"
118: * rows="6"
119: * id="leaveAirport"
120: * toolTip="#{msgs.chooseAirport}"
121: * label="#{msgs.chooseDepartureAirport)" >
122: * <f:facet name="label">
123: * <facet component goes here>
124: * </f:facet>
125: * </ui:listbox>
126: * </pre>
127: * <p>Auto-generated component class.
128: * Do <strong>NOT</strong> modify; all changes
129: * <strong>will</strong> be lost!</p>
130: */
131:
132: public abstract class ListboxBase extends
133: com.sun.rave.web.ui.component.ListSelector {
134:
135: /**
136: * <p>Construct a new <code>ListboxBase</code>.</p>
137: */
138: public ListboxBase() {
139: super ();
140: setRendererType("com.sun.rave.web.ui.Listbox");
141: }
142:
143: /**
144: * <p>Return the identifier of the component family to which this
145: * component belongs. This identifier, in conjunction with the value
146: * of the <code>rendererType</code> property, may be used to select
147: * the appropriate {@link Renderer} for this component instance.</p>
148: */
149: public String getFamily() {
150: return "com.sun.rave.web.ui.Listbox";
151: }
152:
153: // monospace
154: private boolean monospace = false;
155: private boolean monospace_set = false;
156:
157: /**
158: * <p>A property which indicates whether monospaced fonts should be
159: * used.</p>
160: */
161: public boolean isMonospace() {
162: if (this .monospace_set) {
163: return this .monospace;
164: }
165: ValueBinding _vb = getValueBinding("monospace");
166: if (_vb != null) {
167: Object _result = _vb.getValue(getFacesContext());
168: if (_result == null) {
169: return false;
170: } else {
171: return ((Boolean) _result).booleanValue();
172: }
173: }
174: return false;
175: }
176:
177: /**
178: * <p>A property which indicates whether monospaced fonts should be
179: * used.</p>
180: * @see #isMonospace()
181: */
182: public void setMonospace(boolean monospace) {
183: this .monospace = monospace;
184: this .monospace_set = true;
185: }
186:
187: // multiple
188: private boolean multiple = false;
189: private boolean multiple_set = false;
190:
191: /**
192: * <p>Flag indicating that the application user may make select
193: * more than one option from the listbox .</p>
194: */
195: public boolean isMultiple() {
196: if (this .multiple_set) {
197: return this .multiple;
198: }
199: ValueBinding _vb = getValueBinding("multiple");
200: if (_vb != null) {
201: Object _result = _vb.getValue(getFacesContext());
202: if (_result == null) {
203: return false;
204: } else {
205: return ((Boolean) _result).booleanValue();
206: }
207: }
208: return false;
209: }
210:
211: /**
212: * <p>Flag indicating that the application user may make select
213: * more than one option from the listbox .</p>
214: * @see #isMultiple()
215: */
216: public void setMultiple(boolean multiple) {
217: this .multiple = multiple;
218: this .multiple_set = true;
219: }
220:
221: /**
222: * <p>Restore the state of this component.</p>
223: */
224: public void restoreState(FacesContext _context, Object _state) {
225: Object _values[] = (Object[]) _state;
226: super .restoreState(_context, _values[0]);
227: this .monospace = ((Boolean) _values[1]).booleanValue();
228: this .monospace_set = ((Boolean) _values[2]).booleanValue();
229: this .multiple = ((Boolean) _values[3]).booleanValue();
230: this .multiple_set = ((Boolean) _values[4]).booleanValue();
231: }
232:
233: /**
234: * <p>Save the state of this component.</p>
235: */
236: public Object saveState(FacesContext _context) {
237: Object _values[] = new Object[5];
238: _values[0] = super .saveState(_context);
239: _values[1] = this .monospace ? Boolean.TRUE : Boolean.FALSE;
240: _values[2] = this .monospace_set ? Boolean.TRUE : Boolean.FALSE;
241: _values[3] = this .multiple ? Boolean.TRUE : Boolean.FALSE;
242: _values[4] = this.multiple_set ? Boolean.TRUE : Boolean.FALSE;
243: return _values;
244: }
245:
246: }
|