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