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: * <p>
051: * Use the <code>ui:checkboxGroup</code> tag to display two or more
052: * check boxes in a grid layout in the rendered HTML page. The
053: * <code>ui:checkboxGroup</code> tag attributes that you
054: * specify determine how the check boxes are displayed.
055: * </p>
056: * <p>
057: * If the <code>label</code> attribute is specified a
058: * <code>com.sun.rave.web.ui.component.Label</code> component
059: * is rendered before the first checkbox and
060: * identifies the checkbox group. The label component's
061: * <code>for</code> attribute is
062: * set to the <code>id</code> attribute of the first checkbox in
063: * the rendered HTML page.
064: * </p>
065: * <p>
066: * The check boxes are laid out in rows and columns in an HTML
067: * <table> element. The number of rows is defined by the length
068: * of the items array. The number of columns is defined by the columns
069: * attribute. The default layout is a single vertical column.
070: * </p>
071: * <p>
072: * </p>
073: * <p>
074: * The <code>items</code> attribute must be a value binding expression.
075: * The value binding expression assigned to the <code>items</code>
076: * property evaluates to an <code>Object</code> array of
077: * <code>com.sun.rave.web.ui.model.Option</code> instances. Each
078: * instance represents one checkbox. The <code>value</code> property
079: * of an <code>Option</code> instance represents the value of a
080: * selected checkbox.
081: * If the <code>items</code> array is empty nothing is rendered.
082: * </p>
083: * <p>
084: * Zero or more check boxes may be selected.
085: * The <code>selected</code> attribute must also be a value binding
086: * expression that is evaluated to read and write an <code>Object</code>
087: * array. When an array is read from the value binding expression,
088: * it identifies the selected checkboxes. Each element in the array
089: * is an <code>Object</code> value. Each <code>Object</code> value must
090: * be equal to the value property of at least one <code>Option</code>
091: * instance specified in the array obtained from the value binding
092: * expression assigned to the <code>items</code> attribute.
093: * </p>
094: * <p>
095: * The write method of the <code>selected</code> attribute's value
096: * binding expression is called during the <code>UPDATE_MODEL_PHASE</code>
097: * of the JSF lifecyle. If one or more checkboxes are selected
098: * an <code>Object</code> array is passed as an argument to the
099: * write method. This array contains the <code>Object</code>
100: * values of the selected checkboxes.
101: * </p>
102: * <h3>HTML Elements and Layout</h3>
103: * <p>
104: * A <code>ui:checkboxGroup</code> renders one
105: * <code>com.sun.rave.web.ui.component.Checkbox</code> component for
106: * each element in the <code>items</code> array.
107: * See <a href="checkbox.html" target="tagFrame">ui:checkbox</a> for
108: * details on the HTML elements and components rendered for a
109: * checkbox.
110: * </p>
111: * <p>
112: * The value of the <code>name</code> attribute of each
113: * <code>Checkbox</code> component rendered is assigned the
114: * <code>clientId</code> of the <code>CheckboxGroup<code>
115: * component instance associated with this tag. The <code>id</code>
116: * attribute of each <code>Checkbox</code> component rendered
117: * is formed as follows, where <em>cbgrpid</em> is the id of the
118: * <code>CheckboxGroup</code> instance and <em>N</em> is the nth
119: * checkbox.
120: * </p>
121: * <ul>
122: * <li> <em>cbgrpid_N</em></li>
123: * </ul>
124: * <p>
125: * See <a href="checkbox.html" target="tagFrame">ui:checkbox</a> for
126: * details on how the id properties of the components that make up the
127: * checkbox are defined.
128: * </p>
129: * <h3>Client Side Javascript Functions</h3>
130: * <p>
131: * none.
132: * </p>
133: *
134: * <h3>Example</h3>
135: * <b>Example 1: Create a checkbox group</b>
136: * <p>
137: * <code>
138: * <ui:checkboxGroup items="#{rbcbGrp.selections}"</br>
139: * label="#{rbcbGrp.cbGrpLabel}"</br>
140: * toolTip="cbgrp-tooltip"</br>
141: * disabled="false"</br>
142: * tabIndex="4"</br>
143: * selected="#{rbcbGrp.cbvalue}"></br>
144: * </ui:checkboxGroup></br>
145: * </code>
146: * </p>
147: * <p>
148: * This example creates a checkbox group with an identifying
149: * label for the group before the first checkbox. The
150: * data for the checkboxes is obtained from the value binding
151: * expression <code>#{rbcbGrp.selections}</code>. <code>rbcbGrp</code>
152: * is an application defined managed bean and provides the values for
153: * other attributes such as <code>selected</code> to receive the
154: * value of the selected checkboxes in the group.
155: * </p>
156: * <!--
157: * <h3>Theme Identifiers</h3>
158: * <p>
159: * <ul>
160: * <li>CbGrp for the TABLE element.</li>
161: * <li>CbGrpCpt for the TD element containing the group label</li>
162: * <li>CbGrpLbl for the LABEL element used as the CAPTION</li>
163: * <li>CbGrpLblDis for the LABEL used as the CAPTION if the group is disabled</li>
164: * <li>CbGrpRwEv for even TR elements</li>
165: * <li>CbGrpRwOd for odd TR elements</li>
166: * <li>CbGrpClEv for even TD elements</li>
167: * <li>CbGrpClOd for odd TD elements</li>
168: * <li>Cb for the INPUT element</li>
169: * <li>CbDis for the INPUT element for disabled check box </li>
170: * <li>CbLbl for a LABEL element of a check box</li>
171: * <li>CbLblDis for a LABEL element of a disabled check box</li>
172: * <li>CbImg for an IMG element of a check box</li>
173: * <li>CbImgDis for an IMG element of a disabled check box</li>
174: * <li>CbGrp - for the <em>span</em> element that encloses the
175: * entire set of elements rendered for the <code>checkboxGroup</code>.
176: * </li>
177: * </ul>
178: * </p>
179: * -->
180: * <p>Auto-generated component class.
181: * Do <strong>NOT</strong> modify; all changes
182: * <strong>will</strong> be lost!</p>
183: */
184:
185: public abstract class CheckboxGroupBase extends
186: com.sun.rave.web.ui.component.Selector {
187:
188: /**
189: * <p>Construct a new <code>CheckboxGroupBase</code>.</p>
190: */
191: public CheckboxGroupBase() {
192: super ();
193: setRendererType("com.sun.rave.web.ui.CheckboxGroup");
194: }
195:
196: /**
197: * <p>Return the identifier of the component family to which this
198: * component belongs. This identifier, in conjunction with the value
199: * of the <code>rendererType</code> property, may be used to select
200: * the appropriate {@link Renderer} for this component instance.</p>
201: */
202: public String getFamily() {
203: return "com.sun.rave.web.ui.CheckboxGroup";
204: }
205:
206: // columns
207: private int columns = Integer.MIN_VALUE;
208: private boolean columns_set = false;
209:
210: /**
211: * <p>Defines how many columns may be used to lay out the check boxes.
212: * The value must be greater than or equal to one. The default value is one.
213: * Invalid values are ignored and the value is set to one.</p>
214: */
215: public int getColumns() {
216: if (this .columns_set) {
217: return this .columns;
218: }
219: ValueBinding _vb = getValueBinding("columns");
220: if (_vb != null) {
221: Object _result = _vb.getValue(getFacesContext());
222: if (_result == null) {
223: return Integer.MIN_VALUE;
224: } else {
225: return ((Integer) _result).intValue();
226: }
227: }
228: return 1;
229: }
230:
231: /**
232: * <p>Defines how many columns may be used to lay out the check boxes.
233: * The value must be greater than or equal to one. The default value is one.
234: * Invalid values are ignored and the value is set to one.</p>
235: * @see #getColumns()
236: */
237: public void setColumns(int columns) {
238: this .columns = columns;
239: this .columns_set = true;
240: }
241:
242: // visible
243: private boolean visible = false;
244: private boolean visible_set = false;
245:
246: /**
247: * <p>Use the visible attribute to indicate whether the component should be
248: * viewable by the user in the rendered HTML page. If set to false, the
249: * HTML code for the component is present in the page, but the component
250: * is hidden with style attributes. By default, visible is set to true, so
251: * HTML for the component HTML is included and visible to the user. If the
252: * component is not visible, it can still be processed on subsequent form
253: * submissions because the HTML is present.</p>
254: */
255: public boolean isVisible() {
256: if (this .visible_set) {
257: return this .visible;
258: }
259: ValueBinding _vb = getValueBinding("visible");
260: if (_vb != null) {
261: Object _result = _vb.getValue(getFacesContext());
262: if (_result == null) {
263: return false;
264: } else {
265: return ((Boolean) _result).booleanValue();
266: }
267: }
268: return true;
269: }
270:
271: /**
272: * <p>Use the visible attribute to indicate whether the component should be
273: * viewable by the user in the rendered HTML page. If set to false, the
274: * HTML code for the component is present in the page, but the component
275: * is hidden with style attributes. By default, visible is set to true, so
276: * HTML for the component HTML is included and visible to the user. If the
277: * component is not visible, it can still be processed on subsequent form
278: * submissions because the HTML is present.</p>
279: * @see #isVisible()
280: */
281: public void setVisible(boolean visible) {
282: this .visible = visible;
283: this .visible_set = true;
284: }
285:
286: /**
287: * <p>Restore the state of this component.</p>
288: */
289: public void restoreState(FacesContext _context, Object _state) {
290: Object _values[] = (Object[]) _state;
291: super .restoreState(_context, _values[0]);
292: this .columns = ((Integer) _values[1]).intValue();
293: this .columns_set = ((Boolean) _values[2]).booleanValue();
294: this .visible = ((Boolean) _values[3]).booleanValue();
295: this .visible_set = ((Boolean) _values[4]).booleanValue();
296: }
297:
298: /**
299: * <p>Save the state of this component.</p>
300: */
301: public Object saveState(FacesContext _context) {
302: Object _values[] = new Object[5];
303: _values[0] = super .saveState(_context);
304: _values[1] = new Integer(this .columns);
305: _values[2] = this .columns_set ? Boolean.TRUE : Boolean.FALSE;
306: _values[3] = this .visible ? Boolean.TRUE : Boolean.FALSE;
307: _values[4] = this.visible_set ? Boolean.TRUE : Boolean.FALSE;
308: return _values;
309: }
310:
311: }
|