001: /*
002: * License
003: *
004: *
005: * Copyright (c) 2003 Essl Christian. All rights
006: * reserved.
007: *
008: * This Licence is based on the Apache Software Licence Version 1.1.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions
012: * are met:
013: *
014: * 1. Redistributions of source code must retain the above copyright
015: * notice, this list of conditions and the following disclaimer.
016: *
017: * 2. Redistributions in binary form must reproduce the above copyright
018: * notice, this list of conditions and the following disclaimer in
019: * the documentation and/or other materials provided with the
020: * distribution.
021: *
022: * 3. The end-user documentation included with the redistribution,
023: * if any, must include the following acknowledgment:
024: * "This product includes software developed by Christian Essl
025: * and others for project Jucas (http://www.jucas.org/)."
026: * Alternately, this acknowledgment may appear in the software itself,
027: * if and wherever such third-party acknowledgments normally appear.
028: *
029: * 4. The names "Jucas" and "Christian Essl" must
030: * not be used to endorse or promote products derived from this
031: * software without prior written permission. For written
032: * permission, please contact essl_christian@jucas.org.
033: *
034: * 5. Products derived from this software may not be called "Jucas"
035: * or "Christian Essl", nor may "Jucas" or "Christian Essl"
036: * appear in their name, without prior written permission
037: * of Christian Essl (jucas@esslchristian.de).
038: *
039: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
040: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
041: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
042: * DISCLAIMED. IN NO EVENT SHALL CHRISTIAN ESSL OR
043: * OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
044: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
045: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
046: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
047: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
048: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
049: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
050: * SUCH DAMAGE.
051: * ====================================================================
052: *
053: *
054: */
055: package org.jucas.addon.html;
056:
057: /**
058: * An element which can back an html checkbox or options group.<br><br>
059: * It can contain many values and a string of values can be set, which
060: * correspondes to the selection the usageform is as action name
061: * <code>jucas: beanName-of-Element.selected</code> and as value the value(s)
062: * selected.
063: * @author chris
064: *
065: */
066: public class CheckBoxOptionsElement extends StringArrayElement {
067: private String[] selected;
068:
069: /**
070: * Constructor for CheckBoxOptionsElement.
071: */
072: public CheckBoxOptionsElement() {
073: super ();
074: }
075:
076: /**
077: * @see org.jucas.addon.html.StringArrayElement#selectionAttr(java.lang.String)
078: */
079: public String selectionAttr(String value) {
080: return this .containsSelection(value) ? "selected"
081: : EMPTY_STRING;
082: }
083:
084: public String checkedAttr(String value) {
085: return this .containsSelection(value) ? "checked" : EMPTY_STRING;
086: }
087:
088: /**
089: * Returns the selected.
090: * @return String[]
091: */
092: public String[] getSelected() {
093: return selected;
094: }
095:
096: /**
097: * Sets the selected.
098: * @param selected The selected to set
099: */
100: public void setSelected(String[] selected) {
101: this .selected = selected;
102: }
103:
104: public String[] getChecked() {
105: return getSelected();
106: }
107:
108: public void setChecked(String[] checked) {
109: this .setSelected(checked);
110: }
111:
112: public boolean containsSelection(String sel) {
113: String[] sels = this .getSelected();
114: if (sels == null)
115: return false;
116: for (int i = 0; i < sels.length; i++) {
117: if (sels[i] != null && sels[i].equals(sel))
118: return true;
119: }
120: return false;
121: }
122: }
|