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 drop-down menu. 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 dropdown tag</h4>
059: *
060: * <p>Use the <code>items</code> attribute to specify the options
061: * from which the web application user can choose. The value must be
062: * an EL expression that identifies an array, a
063: * <code>java.util.Collection</code> or a <code>java.util.Map</code>
064: * of <code>com.sun.rave.web.ui.model.Option</code>. </p>
065: *
066: * <p>The first time the component is rendered, the option which
067: * corresponds to the value of the <code>selected</code> model object
068: * property is marked as selected, using the <code>equals</code>
069: * method on the model object. </p>
070: *
071: * <p>To optionally specify a label for the component, use the
072: * <code>label</code> attribute, or specify a label facet.</p>
073: *
074: *
075: * <h4>Facets</h4>
076: *
077: * <ul>
078: * <li><code>label</code>: use this facet to specify a custom
079: * component for the label.</li>
080: * </ul>
081: *
082: * <h4>Client-side JavaScript functions</h4>
083: *
084: * <ul>
085: * <li><code>dropDown_setDisabled(<id>, <disabled>)</code>: use
086: * this function to enable/disable the drop-down menu. <code><id></code>
087: * must be the generated id of the component. Set
088: * <code><disabled></code> to true to disable the component,
089: * false to enable it. </li>
090: * <li><code>dropDown_changed(<id>)</code>: this
091: * function is automatically invoked by the drop-down menu's
092: * <code>onchange</code> handler. <code><id></code>
093: * must be the generated id of the component.</li>
094: * </ul>
095: *
096: * <h4>Examples</h4>
097: *
098: * <pre>
099: *
100: * <ui:dropDown selected="#{flightSearch.leaveAirport}"
101: * items="#{dataBean.airports}"
102: * id="leaveAirport"
103: * tooltip="#{msgs.chooseAirport}" label="#{msgs.chooseDepartureAirport}" />
104: *
105: * <ui:dropDown selected="#{flightSearch.leaveAirport}"
106: * items="#{dataBean.airports}"
107: * id="leaveAirport"
108: * tooltip="#{msgs.chooseAirport}"
109: * label="#{msgs.chooseDepartureAirport}" >
110: * <f:facet name="label">
111: * <facet component goes here>
112: * </f:facet>
113: * </ui:dropDown>
114: * </pre>
115: * <p>The dataBean backing bean would include the following definition for the "airports" items:<br>
116: * <pre>
117: * private Option[] airports = null;
118: * // Creates a new instance of backing bean //
119: * public DataBean() {
120: * airports = new Option[11];
121: * airports[0] = new Option("SFO", "San Francisco");
122: * airports[1] = new Option("OAK", "Oakland");
123: * airports[2] = new Option("SAN", "San Diego");
124: * airports[3] = new Option("BOS", "Boston");
125: * airports[4] = new Option("ARN", "Stockholm");
126: * airports[5] = new Option("MNL", "Manila");
127: * airports[6] = new Option("CDG", "Paris");
128: * airports[7] = new Option("PDX", "Portland");
129: * airports[8] = new Option("LAX", "Los Angeles");
130: * airports[9] = new Option("NRT", "Tokyo");
131: * airports[10] = new Option("TBD", "Future Airport");
132: * airports[10].setDisabled(true);
133: * }
134: * public Option[] getAirports() {
135: * return airports;
136: * }
137: * </pre>
138: * <p>Auto-generated component class.
139: * Do <strong>NOT</strong> modify; all changes
140: * <strong>will</strong> be lost!</p>
141: */
142:
143: public abstract class DropDownBase extends
144: com.sun.rave.web.ui.component.ListSelector {
145:
146: /**
147: * <p>Construct a new <code>DropDownBase</code>.</p>
148: */
149: public DropDownBase() {
150: super ();
151: setRendererType("com.sun.rave.web.ui.DropDown");
152: }
153:
154: /**
155: * <p>Return the identifier of the component family to which this
156: * component belongs. This identifier, in conjunction with the value
157: * of the <code>rendererType</code> property, may be used to select
158: * the appropriate {@link Renderer} for this component instance.</p>
159: */
160: public String getFamily() {
161: return "com.sun.rave.web.ui.DropDown";
162: }
163:
164: // action
165: private javax.faces.el.MethodBinding action = null;
166:
167: /**
168: * <p>Method binding representing a method that processes
169: * application actions from this component. This attribute is
170: * only referenced when submitForm is true.</p>
171: */
172: public javax.faces.el.MethodBinding getAction() {
173: if (this .action != null) {
174: return this .action;
175: }
176: ValueBinding _vb = getValueBinding("action");
177: if (_vb != null) {
178: return (javax.faces.el.MethodBinding) _vb
179: .getValue(getFacesContext());
180: }
181: return null;
182: }
183:
184: /**
185: * <p>Method binding representing a method that processes
186: * application actions from this component. This attribute is
187: * only referenced when submitForm is true.</p>
188: * @see #getAction()
189: */
190: public void setAction(javax.faces.el.MethodBinding action) {
191: this .action = action;
192: }
193:
194: // actionListener
195: private javax.faces.el.MethodBinding actionListener = null;
196:
197: /**
198: * <p>Method binding representing a method that receives action
199: * from this, and possibly other, components. The Action Listener is invoked only when
200: * submitForm is true.</p>
201: */
202: public javax.faces.el.MethodBinding getActionListener() {
203: if (this .actionListener != null) {
204: return this .actionListener;
205: }
206: ValueBinding _vb = getValueBinding("actionListener");
207: if (_vb != null) {
208: return (javax.faces.el.MethodBinding) _vb
209: .getValue(getFacesContext());
210: }
211: return null;
212: }
213:
214: /**
215: * <p>Method binding representing a method that receives action
216: * from this, and possibly other, components. The Action Listener is invoked only when
217: * submitForm is true.</p>
218: * @see #getActionListener()
219: */
220: public void setActionListener(
221: javax.faces.el.MethodBinding actionListener) {
222: this .actionListener = actionListener;
223: }
224:
225: // forgetValue
226: private boolean forgetValue = false;
227: private boolean forgetValue_set = false;
228:
229: /**
230: * <p>If this flag is set to true, then the component is always
231: * rendered with no initial selection.</p>
232: */
233: public boolean isForgetValue() {
234: if (this .forgetValue_set) {
235: return this .forgetValue;
236: }
237: ValueBinding _vb = getValueBinding("forgetValue");
238: if (_vb != null) {
239: Object _result = _vb.getValue(getFacesContext());
240: if (_result == null) {
241: return false;
242: } else {
243: return ((Boolean) _result).booleanValue();
244: }
245: }
246: return false;
247: }
248:
249: /**
250: * <p>If this flag is set to true, then the component is always
251: * rendered with no initial selection.</p>
252: * @see #isForgetValue()
253: */
254: public void setForgetValue(boolean forgetValue) {
255: this .forgetValue = forgetValue;
256: this .forgetValue_set = true;
257: }
258:
259: // navigateToValue
260: private boolean navigateToValue = false;
261: private boolean navigateToValue_set = false;
262:
263: /**
264: * <p>If this flag is set to true, then selecting an item from this
265: * component will cause the application to navigate using the
266: * DropDown's value as the action. Use this in place of defining
267: * the navigation outcome using the action MethodBinding. This
268: * applies only if submitForm is true.</p>
269: */
270: public boolean isNavigateToValue() {
271: if (this .navigateToValue_set) {
272: return this .navigateToValue;
273: }
274: ValueBinding _vb = getValueBinding("navigateToValue");
275: if (_vb != null) {
276: Object _result = _vb.getValue(getFacesContext());
277: if (_result == null) {
278: return false;
279: } else {
280: return ((Boolean) _result).booleanValue();
281: }
282: }
283: return false;
284: }
285:
286: /**
287: * <p>If this flag is set to true, then selecting an item from this
288: * component will cause the application to navigate using the
289: * DropDown's value as the action. Use this in place of defining
290: * the navigation outcome using the action MethodBinding. This
291: * applies only if submitForm is true.</p>
292: * @see #isNavigateToValue()
293: */
294: public void setNavigateToValue(boolean navigateToValue) {
295: this .navigateToValue = navigateToValue;
296: this .navigateToValue_set = true;
297: }
298:
299: // submitForm
300: private boolean submitForm = false;
301: private boolean submitForm_set = false;
302:
303: /**
304: * <p>Flag indicating that the form should be submitted when the
305: * value of the component changes.</p>
306: */
307: public boolean isSubmitForm() {
308: if (this .submitForm_set) {
309: return this .submitForm;
310: }
311: ValueBinding _vb = getValueBinding("submitForm");
312: if (_vb != null) {
313: Object _result = _vb.getValue(getFacesContext());
314: if (_result == null) {
315: return false;
316: } else {
317: return ((Boolean) _result).booleanValue();
318: }
319: }
320: return false;
321: }
322:
323: /**
324: * <p>Flag indicating that the form should be submitted when the
325: * value of the component changes.</p>
326: * @see #isSubmitForm()
327: */
328: public void setSubmitForm(boolean submitForm) {
329: this .submitForm = submitForm;
330: this .submitForm_set = true;
331: }
332:
333: /**
334: * <p>Restore the state of this component.</p>
335: */
336: public void restoreState(FacesContext _context, Object _state) {
337: Object _values[] = (Object[]) _state;
338: super .restoreState(_context, _values[0]);
339: this .action = (javax.faces.el.MethodBinding) restoreAttachedState(
340: _context, _values[1]);
341: this .actionListener = (javax.faces.el.MethodBinding) restoreAttachedState(
342: _context, _values[2]);
343: this .forgetValue = ((Boolean) _values[3]).booleanValue();
344: this .forgetValue_set = ((Boolean) _values[4]).booleanValue();
345: this .navigateToValue = ((Boolean) _values[5]).booleanValue();
346: this .navigateToValue_set = ((Boolean) _values[6])
347: .booleanValue();
348: this .submitForm = ((Boolean) _values[7]).booleanValue();
349: this .submitForm_set = ((Boolean) _values[8]).booleanValue();
350: }
351:
352: /**
353: * <p>Save the state of this component.</p>
354: */
355: public Object saveState(FacesContext _context) {
356: Object _values[] = new Object[9];
357: _values[0] = super .saveState(_context);
358: _values[1] = saveAttachedState(_context, action);
359: _values[2] = saveAttachedState(_context, actionListener);
360: _values[3] = this .forgetValue ? Boolean.TRUE : Boolean.FALSE;
361: _values[4] = this .forgetValue_set ? Boolean.TRUE
362: : Boolean.FALSE;
363: _values[5] = this .navigateToValue ? Boolean.TRUE
364: : Boolean.FALSE;
365: _values[6] = this .navigateToValue_set ? Boolean.TRUE
366: : Boolean.FALSE;
367: _values[7] = this .submitForm ? Boolean.TRUE : Boolean.FALSE;
368: _values[8] = this.submitForm_set ? Boolean.TRUE : Boolean.FALSE;
369: return _values;
370: }
371:
372: }
|