001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.faces.component;
030:
031: import java.util.*;
032:
033: import javax.el.*;
034: import javax.faces.context.*;
035: import javax.faces.el.ValueBinding;
036:
037: public class UISelectBoolean extends UIInput {
038: public static final String COMPONENT_FAMILY = "javax.faces.SelectBoolean";
039: public static final String COMPONENT_TYPE = "javax.faces.SelectBoolean";
040:
041: public UISelectBoolean() {
042: setRendererType("javax.faces.Checkbox");
043: }
044:
045: /**
046: * Returns the component family, used to select the renderer.
047: */
048: public String getFamily() {
049: return COMPONENT_FAMILY;
050: }
051:
052: //
053: // properties
054: //
055:
056: public boolean isSelected() {
057: Object value = getValue();
058:
059: return Util.booleanValueOf(value);
060: }
061:
062: public void setSelected(boolean value) {
063: setValue(value);
064: }
065:
066: /**
067: * Returns the value expression with the given name.
068: */
069: @Override
070: public ValueExpression getValueExpression(String name) {
071: if ("selected".equals(name))
072: return super .getValueExpression("value");
073: else
074: return super .getValueExpression(name);
075: }
076:
077: /**
078: * Sets the value expression with the given name.
079: */
080: @Override
081: public void setValueExpression(String name, ValueExpression expr) {
082: if ("selected".equals(name))
083: super .setValueExpression("value", expr);
084: else
085: super .setValueExpression(name, expr);
086: }
087:
088: /**
089: * Returns the value binding with the given name.
090: */
091: @Override
092: public ValueBinding getValueBinding(String name) {
093: if ("selected".equals(name))
094: return super .getValueBinding("value");
095: else
096: return super .getValueBinding(name);
097: }
098:
099: /**
100: * Sets the value binding with the given name.
101: */
102: @Override
103: public void setValueBinding(String name, ValueBinding expr) {
104: if ("selected".equals(name))
105: super .setValueBinding("value", expr);
106: else
107: super .setValueBinding(name, expr);
108: }
109:
110: //
111: // state
112: //
113:
114: public Object saveState(FacesContext context) {
115: return super .saveState(context);
116: }
117:
118: public void restoreState(FacesContext context, Object value) {
119: super.restoreState(context, value);
120: }
121: }
|