Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]

    1   /*
    2    * $Id: UISelectBoolean.java,v 1.40 2007/04/27 22:00:05 ofung Exp $
    3    */
    4   
    5   /*
    6    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    7    * 
    8    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   package javax.faces.component;
   42   
   43   import javax.el.ValueExpression;
   44   import javax.faces.el.ValueBinding;
   45   
   46   
   47   /**
   48    * <p><strong>UISelectBoolean</strong> is a {@link UIComponent} that
   49    * represents a single boolean (<code>true</code> or <code>false</code>) value.
   50    * It is most commonly rendered as a checkbox.</p>
   51    *
   52    * <p>By default, the <code>rendererType</code> property must be set to
   53    * "<code>javax.faces.Checkbox</code>".  This value can be changed by
   54    * calling the <code>setRendererType()</code> method.</p>
   55    */
   56   
   57   public class UISelectBoolean extends UIInput {
   58   
   59   
   60       // ------------------------------------------------------ Manifest Constants
   61   
   62   
   63       /**
   64        * <p>The standard component type for this component.</p>
   65        */
   66       public static final String COMPONENT_TYPE = "javax.faces.SelectBoolean";
   67   
   68   
   69       /**
   70        * <p>The standard component family for this component.</p>
   71        */
   72       public static final String COMPONENT_FAMILY = "javax.faces.SelectBoolean";
   73   
   74   
   75       // ------------------------------------------------------------ Constructors
   76   
   77   
   78       /**
   79        * <p>Create a new {@link UISelectBoolean} instance with default
   80        * property values.</p>
   81        */
   82       public UISelectBoolean() {
   83   
   84           super();
   85           setRendererType("javax.faces.Checkbox");
   86   
   87       }
   88   
   89   
   90       // -------------------------------------------------------------- Properties
   91   
   92   
   93       public String getFamily() {
   94   
   95           return (COMPONENT_FAMILY);
   96   
   97       }
   98   
   99   
  100       /**
  101        * <p>Return the local value of the selected state of this component.
  102        * This method is a typesafe alias for <code>getValue()</code>.</p>
  103        */
  104       public boolean isSelected() {
  105   
  106           Boolean value = (Boolean) getValue();
  107           if (value != null) {
  108               return (value.booleanValue());
  109           } else {
  110               return (false);
  111           }
  112   
  113       }
  114   
  115   
  116       /**
  117        * <p>Set the local value of the selected state of this component.
  118        * This method is a typesafe alias for <code>setValue()</code>.</p>
  119        *
  120        * @param selected The new selected state
  121        */
  122       public void setSelected(boolean selected) {
  123   
  124           if (selected) {
  125               setValue(Boolean.TRUE);
  126           } else {
  127               setValue(Boolean.FALSE);
  128           }
  129   
  130       }
  131   
  132   
  133       // ---------------------------------------------------------------- Bindings
  134   
  135   
  136       /**
  137        * <p>Return any {@link ValueBinding} set for <code>value</code> if a
  138        * {@link ValueBinding} for <code>selected</code> is requested; otherwise,
  139        * perform the default superclass processing for this method.</p>
  140        *
  141        * <p>Rely on the superclass implementation to wrap the returned
  142        * <code>ValueExpression</code> in a <code>ValueBinding</code>.</p>
  143        *
  144        * @param name Name of the attribute or property for which to retrieve
  145        *  a {@link ValueBinding}
  146        *
  147        * @throws NullPointerException if <code>name</code>
  148        *  is <code>null</code>
  149        *
  150        * @deprecated This has been replaced by {@link
  151        * #getValueExpression}.
  152        */
  153       public ValueBinding getValueBinding(String name) {
  154   
  155           if ("selected".equals(name)) {
  156               return (super.getValueBinding("value"));
  157           } else {
  158               return (super.getValueBinding(name));
  159           }
  160   
  161       }
  162   
  163   
  164       /**
  165        * <p>Store any {@link ValueBinding} specified for <code>selected</code>
  166        * under <code>value</code> instead; otherwise, perform the default
  167        * superclass processing for this method.</p>
  168        *
  169        * <p>Rely on the superclass implementation to wrap the argument
  170        * <code>ValueBinding</code> in a <code>ValueExpression</code>.</p>
  171        *
  172        * @param name Name of the attribute or property for which to set
  173        *  a {@link ValueBinding}
  174        * @param binding The {@link ValueBinding} to set, or <code>null</code>
  175        *  to remove any currently set {@link ValueBinding}
  176        *
  177        * @throws NullPointerException if <code>name</code>
  178        *  is <code>null</code>
  179        *
  180        * @deprecated This has been replaced by {@link #setValueExpression}.
  181        */
  182       public void setValueBinding(String name, ValueBinding binding) {
  183   
  184           if ("selected".equals(name)) {
  185               super.setValueBinding("value", binding);
  186           } else {
  187               super.setValueBinding(name, binding);
  188           }
  189   
  190       }
  191   
  192       /**
  193        * <p>Return any {@link ValueExpression} set for <code>value</code>
  194        * if a {@link ValueExpression} for <code>selected</code> is
  195        * requested; otherwise, perform the default superclass processing
  196        * for this method.</p>
  197        *
  198        * @param name Name of the attribute or property for which to retrieve
  199        *  a {@link ValueExpression}
  200        *
  201        * @throws NullPointerException if <code>name</code>
  202        *  is <code>null</code>
  203        * @since 1.2
  204        */
  205       public ValueExpression getValueExpression(String name) {
  206   
  207           if ("selected".equals(name)) {
  208               return (super.getValueExpression("value"));
  209           } else {
  210               return (super.getValueExpression(name));
  211           }
  212   
  213       }
  214       
  215       /**
  216        * <p>Store any {@link ValueExpression} specified for <code>selected</code>
  217        * under <code>value</code> instead; otherwise, perform the default
  218        * superclass processing for this method.</p>
  219        *
  220        * @param name Name of the attribute or property for which to set
  221        *  a {@link ValueExpression}
  222        * @param binding The {@link ValueExpression} to set, or <code>null</code>
  223        *  to remove any currently set {@link ValueExpression}
  224        *
  225        * @throws NullPointerException if <code>name</code>
  226        *  is <code>null</code>
  227        * @since 1.2
  228        */
  229       public void setValueExpression(String name, ValueExpression binding) {
  230   
  231           if ("selected".equals(name)) {
  232               super.setValueExpression("value", binding);
  233           } else {
  234               super.setValueExpression(name, binding);
  235           }
  236   
  237       }
  238   
  239   
  240   }

Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]