Source Code Cross Referenced for CheckboxBase.java in  » IDE-Netbeans » visualweb.api.designer » com » sun » rave » web » ui » component » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » com.sun.rave.web.ui.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:checkbox</code> tag to display a checkbox
052:         * in the rendered HTML page. The tag can be used as a single
053:         * checkbox or as one checkbox among a group of checkboxes. A group
054:         * of checkboxes represents a multiple selection list which can have any
055:         * number of checkboxes selected, or none selected. A checkbox can
056:         * represent a value of a class type such as <code>Boolean, Byte, Character,
057:         * Double, Float, Integer, Long, Short, String</code> or the primitive form
058:         * of one of these class types.
059:         * A checkbox may also represent an application defined object value.
060:         * </p>
061:         * <p>
062:         * A <code>Boolean</code> value is useful for indicating whether
063:         * an item, such as a table row, is selected. A <code>String</code>
064:         * value is useful for passing values for checkbox selections made in the
065:         * interface. An application defined <code>Object</code> value or class
066:         * instance can be used to hold more information related to a checkbox
067:         * selection.
068:         * </p>
069:         * <p>
070:         * A single checkbox can be used to represent several types of data:
071:         * </p>
072:         * <ul>
073:         *   <li>a boolean control</li>
074:         *   <li>a string value that is related to the checkbox selection</li>
075:         *   <li>an object value defined by the application</li>
076:         * </ul>
077:         * <p>
078:         * A group of checkboxes can be used to represent:
079:         * </p>
080:         * <ul>
081:         *   <li>string values that are related to the checkbox selections</li>
082:         *   <li>object values defined by the application</li>
083:         * </ul>
084:         * <p>
085:         * Note: Another tag for rendering checkboxes is
086:         * <code>ui:checkboxGroup</code>, which imposes a grid layout on a group
087:         * of checkboxes. The <code>checkbox</code> tag is useful in
088:         * situations where the <code>checkboxGroup</code> tag layout is not
089:         * desirable, such as in a table row.
090:         * </p>
091:         * <p>
092:         * </p>
093:         * <h3>Detecting a selected checkbox</h3>
094:         * <p>
095:         * The <code>checkbox</code> tag uses both the <code>selected</code>
096:         * and <code>selectedValue</code> attributes to pass information about
097:         * the checkbox's selection status. The <code>selected</code>
098:         * attribute is used to indicate that the checkbox is selected, and should
099:         * have a check mark displayed in the page. The <code>selectedValue</code>
100:         * attribute is used to pass a data value for the
101:         * checkbox. A checkbox is considered to be selected when the value of the
102:         * <code>selected</code> attribute is equal to the value of
103:         * the <code>selectedValue</code> attribute. You can display a checkbox as
104:         * selected on the initial viewing of the page by assigning the same value
105:         * to the <code>selectedValue</code> and the <code> selected</code> attributes.
106:         * </p>
107:         * <p>
108:         * If the <code>selectedValue</code> attribute is not specified or its
109:         * value is <code>null</code> then the checkbox behaves like a
110:         * boolean control. If the checkbox is selected, the value of the
111:         * <code>selected</code> attribute is a true <code>Boolean</code>
112:         * instance. If the checkbox is not selected, the value of the
113:         * <code>selected</code> attribute will be a false <code>Boolean</code>
114:         * instance.
115:         * </p>
116:         * <p><em>
117:         * Note that a value binding expression that evaluates to a
118:         * primitive value can be assigned to the <code>selected</code>
119:         * and <code>selectedValue</code> attributes.
120:         * </em>
121:         * </p>
122:         * <p>
123:         * When checkboxes are part of a group, an <code>ArrayList</code> of
124:         * selected checkboxes is maintained. If any checkboxes within a group are
125:         * selected, a request attribute whose name is the value of the <code>name</code>
126:         * attribute is created and added to the <code>RequestMap</code>. The
127:         * request attribute value is an <code>ArrayList</code> containing the
128:         * value of the <code>selectedValue</code> attribute of each selected
129:         * checkbox. If no checkboxes are selected, no request attribute is
130:         * created. The <code>selected</code> attribute of each selected checkbox
131:         * within the group will also contain the value of the <code>selectedValue</code>
132:         * attribute of the respective selected checkbox.<br/>
133:         * </p>
134:         * The <code>Checkbox</code> class provides a convenience method for
135:         * obtaining the selected checkboxes in a group:
136:         * </p>
137:         * <p>
138:         * public static ArrayList getSelected(String groupName);
139:         * </p>
140:         * <p> where <code>groupName</code> is the value of the <code>name</code>
141:         * attribtue. Note that unlike the <code>selected</code> and
142:         * <code>selectedValue</code> attributes, the return value of this method
143:         * is always an ArrayList of class instances and not primitive values.
144:         * </p>
145:         * <h3>Using a <code>checkbox</code> tag as a boolean control</h3>
146:         * <p>
147:         * If the <code>selectedValue</code> attribute is not specified or its
148:         * value is <code>null</code> then the checkbox behaves like a
149:         * boolean control.
150:         * </p>
151:         * <p>
152:         * To use the <code>checkbox</code> tag as a boolean control, do not
153:         * specify a value for the <code>selectedValue</code> attribute. The
154:         * checkbox is selected if the <code>selected</code> attribute is not
155:         * null and has the value of a true <code>Boolean</code> instance or
156:         * a <code>boolean</code> primitive value.
157:         * If the checkbox is not selected, then the value of the
158:         * <code>selected</code> attribute is a false <code>Boolean</code> instance
159:         * or <code>boolean</code> primitive.
160:         * </p>
161:         * <p>
162:         * Normally the value of the <code>selectedValue</code> attribute is
163:         * specified as the value of the &lt;input&gt; HTML element. When a
164:         * checkbox is behaving as a boolean control the value of the &lt;input&gt;
165:         * element is the <code>clientId</code> of the checkbox.
166:         * </p>
167:         * <p><em>
168:         * Note that using a boolean checkbox in a group and
169:         * referencing the request attribute for the selected checkboxes is not
170:         * useful, since the value of the request attribute will be an <code>ArrayList
171:         * </code> of indistinguishable <code>true</code> values.
172:         * </em>
173:         * </p>
174:         * <h3>Using a <code>checkbox</code> tag to represent an application defined
175:         * value</h3>
176:         * <p>
177:         * The <code>selectedValue</code> attribute can be assigned an
178:         * application defined object value to represent the value of a selected
179:         * checkbox. If the checkbox is selected, the value of the <code>selected</code>
180:         * attribute is assigned the value of the <code>selectedValue</code>
181:         * attribute.
182:         * </p>
183:         * <p>
184:         * If the value of the <code>selectedValue</code> attribute is an
185:         * application defined object, a converter must be registered
186:         * to convert to and from a <code>String</code> value. The
187:         * converter is used to encode the checkbox value
188:         * as the value of the HTML &lt;input&gt; element and to decode the
189:         * submitted value in a request. In addition the object must support an
190:         * <code>equals</code> method that returns <code>true</code> when the 
191:         * value of the <code>selectedValue</code> attribute is compared to
192:         * the <code>selected</code> attribute value in order to detect a
193:         * selected checkbox.
194:         * </p>
195:         * <h3>Using a <code>checkbox</code> tag as one control in a group</h3>
196:         * <p>
197:         * The <code>name</code> attribute determines whether a
198:         * checkbox is part of a group. A checkbox is treated as part of a group
199:         * of checkboxes if the <code>name</code> attribute of the checkbox is
200:         * assigned a value equal to the <code>name</code> attribute of the other
201:         * checkboxes in the group. In other words, all checkboxes of a group have the
202:         * same <code>name</code> attribute value. The group behaves
203:         * like a multiple selection list, where zero or more checkboxes
204:         * can be selected. The value of the name attribute must
205:         * be unique within the scope of the &lt;form&gt; element containing the
206:         * checkboxes.
207:         * </p>
208:         * <h3>Facets</h3>
209:         * <p>
210:         * The following facets are supported:
211:         * </p>
212:         * <ul>
213:         *   <li><em>image</em> If the image facet exists, it is rendered to the
214:         *       immediate right hand side of the checkbox.
215:         *   <li><em>label</em> If the label facet exists, it is rendered to the
216:         * 	immediate right of the image, or to the immediate right of the
217:         * 	checkbox if no image is rendered.
218:         * </ul>
219:         * <h3>Examples</h3>
220:         * <h4>Example 1: Single boolean checkbox with value binding.</h4>
221:         * <code>
222:         * &lt;ui:checkbox id="cb1" selected="#{tldRbCbExample.selectedCb1}"/&gt;
223:         * </code>
224:         * <p>
225:         * The value binding <code>#{tldRbCbExample.selectedCb1}</code> implies that
226:         * there are two methods implemented in the <code>tldRbCbExample</code>
227:         * managed bean.
228:         * <ul>
229:         * <li>public void setSelectedCb1(boolean selected)</li>
230:         * <li>public boolean getSelectedCb1()</li>
231:         * </ul>
232:         * The <code>getSelectedCb1</code> method will be called to determine the checked
233:         * state of the checkbox during rendering.<br/>
234:         * When the tag is first rendered, its initial checked state is
235:         * determined by the return value of <code>getSelectedCb1</code>. If it returns
236:         * <code>true</code> the checkbox will be checked on the HTML page and 
237:         * not checked if it returns <code>false</code><br/>
238:         * When the checkbox is checked by the user the <code>setSelectedCb1</code> method
239:         * will be called with a <code>boolean</code> argument equal to <code>true</code>.
240:         * When it is unchecked the method will be called with a <code>boolean</code>
241:         * argument equal to <code>false</code>.<br/>
242:         * </p>
243:         * <p>No image or label will be displayed by this example.</p>
244:         * 
245:         * <h4>Example 2: Single boolean checkbox with value binding,
246:         * that displays an image and a label.</h4>
247:         * <code>
248:         * &lt;ui:checkbox id="cb2" selected="#{tldRbCbExample.selectedCb2}"
249:         * imageURL="tree_server.gif label="Server"/&gt;
250:         * </code>
251:         * <p>
252:         * The behavior of this checkbox is the same as example one.<br/>
253:         * In this example an image and a label are displayed next to the checkbox. Both
254:         * the <code>imageURL</code> and <code>label</code> attributes may be assigned
255:         * value binding expressions instead of literal values.
256:         * </p>
257:         * <h4>Example 3: Single String valued checkbox with value binding.</h4>
258:         * <code>
259:         * &lt;ui:checkbox id="cb3" label="Printer" selectedValue="Printer"
260:         * selected="#{tldRbCbExample.selectedCb3}"/&gt;
261:         * </code>
262:         * <p>
263:         * The value binding <code>#{tldRbCbExample.selectedCb3}</code> implies that
264:         * there are two methods implemented in the <code>tldRbCbExample</code>
265:         * managed bean. Because the <code>selectedValue</code> attribute is a
266:         * <code>String</code> the expected method signatures will be:
267:         * <ul>
268:         * <li>public void setSelectedCb3(String selected)</li>
269:         * <li>public String getSelectedCb3()</li>
270:         * </ul>
271:         * The <code>getSelectedCb3</code> method will be called to determine the
272:         * checked state of the checkbox during rendering.<br/>
273:         * When the tag is first rendered, its initial checked state is determined by
274:         * the return value of <code>getSelectedCb3</code>. With a <code>String</code>
275:         * valued checkbox, this checkbox will be checked only if the
276:         * <code>getSelectedCb3</code> method returns "Printer", since that is the value
277:         * of the checkbox as dictated by the <code>selectedValue="Printer"</code>
278:         * attribute. If the <code>getSelectedCb3</code> method returns anything else,
279:         * the checkbox will not be checked.<br/>
280:         * When the checkbox is checked by the user the <code>setSelectedCb3</code>
281:         * method will be called with a <code>String</code> argument equal to "Printer".
282:         * When it is unchecked the method will be called with a null <code>String</code>
283:         * argument.
284:         * </p>
285:         * <h4>Example 4: Single Object valued checkbox with value bindings and a label.</h4>
286:         * <code>
287:         * &lt;ui:checkbox id="cb4" label="Printer"
288:         * 	selectedValue="#{tldRbCbExample.selectedValueCb4}"
289:         * 	selected="#{tldRbCbExample.selectedCb4}"
290:         * 	converter="#{tldRbCbExample.printerConverter}"/&gt;
291:         * </code>
292:         * <p>
293:         * The value bindings <code>#{tldRbCbExample.selectedCb4}</code> and
294:         * <code>#{tldRbCbExample.selectedValueCb4}</code> imply the following methods
295:         * are implemented in the <code>tldRbCbExample</code> managed bean. Let's say
296:         * the object value is an instance of the "Printer" class, then the expected
297:         * method signatures will be:
298:         * </p>
299:         * <p>
300:         * <ul>
301:         * <li>public void setSelectedCb4(Printer selected)</li>
302:         * <li>public Printer getSelectedCb4()</li>
303:         * <li>public void setSelectedValueCb4(Printer selected)</li>
304:         * <li>public Printer getSelectedValueCb4()</li>
305:         * </ul>
306:         * </p>
307:         * A Printer class might look like:
308:         * <p>
309:         * <code><pre>
310:         *     public static class Printer {
311:         * 	private String name;
312:         * 	private String location;
313:         * 	public Printer(String name, String location) {
314:         * 	    this.name = name;
315:         * 	    this.location = location;
316:         * 	}
317:         * 	public String getName() {
318:         * 	    return name;
319:         * 	}
320:         * 	public String getLocation() {
321:         * 	    return location;
322:         * 	}
323:         * 	public boolean equals(Printer p) {
324:         * 	    return this.name.equals(p.getName()) &&
325:         * 		    this.location.equals(p.getLocation());
326:         * 	}
327:         *     };
328:         * </pre>
329:         * </code>
330:         * </p>
331:         * <p>
332:         * Since this is an application defined object value, the application must supply
333:         * a converter, as indicated in the example. The converter attribute's
334:         * value binding expression implies a method in the <code>tldRbCbExample</code>
335:         * managed bean called
336:         * </p>
337:         * <p>
338:         * <code>public Converter getPrinterConverter();</code>.
339:         * </p>
340:         * The converter class might look like:
341:         * <code><pre>
342:         *     public class PrinterConverter implements javax.faces.convert.Converter {
343:         * 	public PrinterConverter() {
344:         * 	}
345:         * 	public String getAsString(FacesContext context, 
346:         * 		UIComponent component, Object value) {
347:         * 	    if (!(value instanceof Printer)) {
348:         * 		throw new ConverterException("Not a Printer value");
349:         * 	    }
350:         * 	    return ((Printer)value).getName();
351:         * 	}
352:         * 	public Object getAsObject(FacesContext context, 
353:         * 		UIComponent component, String value) {
354:         * 	    if (!value.equals("printer1")) {
355:         * 		throw new ConverterException("Unrecognized printer: " + value);
356:         * 	    }
357:         * 	    return printerDb.getPrinter("printer1");
358:         * 	}
359:         *     };
360:         * </pre>
361:         * </code>
362:         * </p>
363:         * <p>
364:         * The <code>getSelectedCb4</code> method will be called to determine the
365:         * checked state of the checkbox during rendering.<br/> When the tag
366:         * is first rendered, its initial state is determined by the return value of
367:         * <code>getSelectedCb4</code>. With an <code>Object</code> valued checkbox,
368:         * this checkbox will be checked only if the <code>getSelectedCb4</code> method
369:         * returns a Printer instance that equals the Printer instance returned
370:         * by the <code>getSelectedValueCb4</code> method.<br/>
371:         * If the <code>getSelectedCb4</code> method returns a Printer instance that
372:         * is not equal as determined by
373:         * <code>getSelectedValueCb4().equals(getSelectedCb4())</code> the checkbox
374:         * will not be checked.<br/>
375:         * When the checkbox is checked by the user the <code>setSelectedCb4</code>
376:         * method will be called with the Printer instance returned by the converter.
377:         * </p>
378:         * 
379:         * <h4>Example 5: Grouped Integer valued checkboxes in a table.</h4>
380:         * <p>
381:         * The following example shows a common use case for checkboxes in
382:         * a table. The checkboxes are used to select zero or more rows
383:         * for processing. The checkbox state does not need to be
384:         * stored. The selected row indexes can be obtained directly as
385:         * <code>Integer</code> values from the <code>ArrayList</code> of
386:         * selected checkboxes maintained by the checkbox
387:         * in the action callback <code>#{tldRbCbExample.table5process}</code>.<br/>
388:         * The markup in bold is how you would specify a checkbox tag for this purpose.
389:         * The <code>selectedValue</code> value binding,
390:         * <code>#{tldRbCbExample.currentRow1}</code>
391:         * is implemented to return the current row in the <code>table5row1</code>
392:         * tableRow tag.
393:         * </p>
394:         * <p>
395:         * <code><pre>
396:         *     &lt;ui:table id="table5"&gt;
397:         * 	&lt;ui:tableRow id="table5row1"
398:         * 	    sourceData="#{tldRbCbExample.table5row1data}"
399:         * 	    sourceVar="table5data"
400:         * 	    binding="#{tldRbCbExample.table5row1}"&gt;
401:         * 	    &lt;ui:tableColumn id="col1"&gt;
402:         * 
403:         * 		&lt;f:facet name="header"&gt;
404:         * 		    &lt;ui:tableHeader id="header1"
405:         * 			deselectAllButton="true"
406:         * 			selectAllButton="true"
407:         * 			selectId="cb5"/&gt;
408:         * 		&lt;/f:facet&gt;
409:         * 
410:         * 		<b>
411:         * 		&lt;ui:checkbox id="cb5" name="cb5Grp" 
412:         * 			selectedValue="#{tldRbCbExample.currentRow1}"&gt;
413:         * 		&lt;/ui:checkbox&gt;
414:         * 		</b>
415:         * 
416:         * 	    &lt;/ui:tableColumn&gt;
417:         * 	    &lt;ui:tableColumn id="col2"&gt;
418:         * 		&lt;f:facet name="header"&gt;
419:         * 		    &lt;ui:staticText text="Application Data"/&gt;
420:         * 		&lt;/f:facet&gt;
421:         * 
422:         * 		&lt;ui:staticText text="#{table5data.text}"/&gt;
423:         * 
424:         * 	    &lt;/ui:tableColumn&gt;
425:         * 	&lt;/ui:tableRow&gt;
426:         * 	&lt;f:facet name="tableActionsBottom"&gt;
427:         * 	   &lt;ui:button id="table5process"
428:         * 		action="#{tldRbCbExample.table5process}"
429:         * 		text="Process Checked"/&gt;
430:         * 	&lt;/f:facet&gt;
431:         *     &lt;/ui:table&gt;
432:         * </pre>
433:         * </code>
434:         * </p>
435:         * <p>
436:         * See <a href="table.html" target="tagFrame">ui:table</a> for details
437:         * on using the <code>&lt;ui:table&gt;</code> tag and other table child tags
438:         * and facets.
439:         * </p>
440:         * <p>
441:         * </p>
442:         * <p>
443:         * Normally when checkboxes are contained within a <code>ui:tableRow</code>
444:         * the application MUST provide a value binding for the <code>selected</code>
445:         * attribute and any attribute that is expected to maintain its state. This
446:         * is because the table only creates a single instance of the checkbox for
447:         * all rows. It depends on a model to provide the storage for the attribute
448:         * values, as it iterates over the rows in the dataset.<br/>
449:         * In this example, we don't need to maintain the state across requests because
450:         * the rows just need to be selected for processing. Once the processing
451:         * is complete, the checkbox no longer needs to be checked.
452:         * <p>
453:         * The following code shows how the <code>table5process</code> action
454:         * method obtains the selected checkbox values from the request map.
455:         * It calls a static member on <code>Checkbox</code> to return the
456:         * <code>ArrayList</code>
457:         * </p>
458:         * <p>
459:         * <code>public static ArrayList getSelected(String groupName)</code>
460:         * </p>
461:         * <code><pre>
462:         *     public void table5process() {
463:         * 
464:         * 	// Checkbox.getSelected(String groupName) is
465:         * 	// a static convenience method that obtains the 
466:         * 	// ArrayList of selected checkboxes from the request map
467:         * 	// <em>ONLY when the checkboxes are part of a group</em>.
468:         * 	//
469:         * 	ArrayList al = Checkbox.getSelected("cb5Grp");
470:         * 	if (al != null) {
471:         * 	    ListIterator li = al.listIterator();
472:         * 	    while (li.hasNext()) {
473:         * 		processRow(((Integer)li.next()).intValue());
474:         * 	    }
475:         * 	}
476:         *     }
477:         * </pre></code>
478:         * <p>
479:         * <h4>Example 6: Grouped boolean checkboxes in a table, using value bindings to
480:         * maintain the state.</h4>
481:         * <p>
482:         * This example is similar to Example 5, but it maintains the state of checkboxes
483:         * across requests, by specifying a value binding for the selected attribute.
484:         * A simple way to store the checkbox state is to store the state with the
485:         * row data.
486:         * </p>
487:         * <code>
488:         * 	&lt;ui:checkbox id="cb6" selected="#{table6data.selected}"&gt;
489:         * 	&lt;/ui:checkbox&gt;
490:         * </code>
491:         * <p>
492:         * The value binding <code>#{table6data.selected}</code> references a boolean
493:         * member in the row data for storing and retrieving the checkbox state.
494:         * Notice also that it is not necessary to group the checkboxes by specifying
495:         * a value for the <code>name</code> attribute. It is not useful to specify
496:         * boolean checkboxes in a group, in order to obtain the list of selected
497:         * checkboxes from the request map. The list will consist of indistinguishable
498:         * <code>true</code> values; one for each selected checkbox.
499:         * </p>
500:         * <h3>HTML Elements and Layout</h3>
501:         * <p>
502:         * A <code>checkbox</code> is rendered as at least one HTML &lt;span&gt; 
503:         * element and one &lt;input&gt; element of type <em>checkbox</em>. 
504:         * Each checkbox may consist of the following elements and components:
505:         * </p>
506:         * <ul>
507:         *   <li>a &lt;span&gt; element</li>
508:         *   <li>an &lt;input&gt; element of type <em>checkbox</em></li>
509:         *   <li>an optional image, if the <code>imageURL</code>
510:         *       attribute or an <code>image</code> facet is specified. If the
511:         *       <code>imageURL</code> is specified and no image facet exists
512:         *       a <code>com.sun.rave.web.ui.component.ImageComponent</code> is created
513:         *       and rendered. If an <code>image</code> facet is specified then the 
514:         *       component specified by the facet is rendered.</li>
515:         *   <li>an optional label, if the <code>label</code>
516:         *       attribute or a <code>label</code> facet is specified. If the
517:         *       <code>label</code> attribute is specified and no label facet exists
518:         *       a <code>com.sun.rave.web.ui.component.Label</code> is created and rendered
519:         *       If a <code>label</code> facet is specified then 
520:         *       the component specified by the facet is rendered.</li>
521:         * </ul>
522:         * <p>
523:         * The id attributes for HTML elements and components are constructed as follows,
524:         * where <em>cid</em> is the <code>clientId</code> of the component
525:         * being rendered.
526:         * </p>
527:         * <ul>
528:         *   <li> <em>cid</em><b>_span</b> for the &lt;span&gt; element</li>
529:         *   <li> <em>cid</em> for the &lt;input&gt; element</li>
530:         *   <li> <em>cid</em><b>_image</b> for the image component if created.</li>
531:         *   <li> <em>cid</em><b>_label</b> for the label component if created.</li>
532:         * </ul>
533:         * <h3>Client Side Javascript Functions </h3>
534:         * <ul>
535:         *   <li><em>checkbox_setChecked(elementId, checked)</em>: Set the 
536:         * 	  checked property for a checkbox with the given element id,
537:         * 	  <em>elementId</em>.
538:         * 	  If <em>checked</em> is true, the checkbox is checked.
539:         * 	  If <em>checked</em> is false, the checkbox is unchecked.</li>
540:         * </ul>
541:         * <p></p>
542:         * <!--
543:         * 	<h3>Theme Identifiers</h3>
544:         * <p>
545:         * 	<lo>
546:         * 	<li>Cb for the INPUT element</li>
547:         * 	<li>CbDis for the INPUT element for disabled checkbox</li>
548:         * 	<li>CbLbl for a LABEL element of a checkbox</li>
549:         * 	<li>CbLblDis for a LABEL element of a disabled checkbox</li>
550:         * 	<li>CbImg for an IMG element of a checkbox</li>
551:         * 	<li>CbImgDis for an IMG element of a disabled checkbox</li>
552:         * 	</lo>
553:         * </p>
554:         * -->
555:         * <p>Auto-generated component class.
556:         * Do <strong>NOT</strong> modify; all changes
557:         * <strong>will</strong> be lost!</p>
558:         */
559:
560:        public abstract class CheckboxBase extends
561:                com.sun.rave.web.ui.component.RbCbSelector {
562:
563:            /**
564:             * <p>Construct a new <code>CheckboxBase</code>.</p>
565:             */
566:            public CheckboxBase() {
567:                super ();
568:                setRendererType("com.sun.rave.web.ui.Checkbox");
569:            }
570:
571:            /**
572:             * <p>Return the identifier of the component family to which this
573:             * component belongs.  This identifier, in conjunction with the value
574:             * of the <code>rendererType</code> property, may be used to select
575:             * the appropriate {@link Renderer} for this component instance.</p>
576:             */
577:            public String getFamily() {
578:                return "com.sun.rave.web.ui.Checkbox";
579:            }
580:
581:            // labelLevel
582:            private int labelLevel = Integer.MIN_VALUE;
583:            private boolean labelLevel_set = false;
584:
585:            /**
586:             * <p>Sets the style level for the generated label, provided the
587:             *       label attribute has been set. Valid values are 1 (largest), 2 and
588:             *       3 (smallest). The default value is 3.</p>
589:             */
590:            public int getLabelLevel() {
591:                if (this .labelLevel_set) {
592:                    return this .labelLevel;
593:                }
594:                ValueBinding _vb = getValueBinding("labelLevel");
595:                if (_vb != null) {
596:                    Object _result = _vb.getValue(getFacesContext());
597:                    if (_result == null) {
598:                        return Integer.MIN_VALUE;
599:                    } else {
600:                        return ((Integer) _result).intValue();
601:                    }
602:                }
603:                return 3;
604:            }
605:
606:            /**
607:             * <p>Sets the style level for the generated label, provided the
608:             *       label attribute has been set. Valid values are 1 (largest), 2 and
609:             *       3 (smallest). The default value is 3.</p>
610:             * @see #getLabelLevel()
611:             */
612:            public void setLabelLevel(int labelLevel) {
613:                this .labelLevel = labelLevel;
614:                this .labelLevel_set = true;
615:            }
616:
617:            /**
618:             * <p>Restore the state of this component.</p>
619:             */
620:            public void restoreState(FacesContext _context, Object _state) {
621:                Object _values[] = (Object[]) _state;
622:                super .restoreState(_context, _values[0]);
623:                this .labelLevel = ((Integer) _values[1]).intValue();
624:                this .labelLevel_set = ((Boolean) _values[2]).booleanValue();
625:            }
626:
627:            /**
628:             * <p>Save the state of this component.</p>
629:             */
630:            public Object saveState(FacesContext _context) {
631:                Object _values[] = new Object[3];
632:                _values[0] = super .saveState(_context);
633:                _values[1] = new Integer(this .labelLevel);
634:                _values[2] = this.labelLevel_set ? Boolean.TRUE : Boolean.FALSE;
635:                return _values;
636:            }
637:
638:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.