Save This Page
Home » mojarra-1.2_09-b02-FCS-source » javax.faces.component » [javadoc | source]
    1   /*
    2    * $Id: UISelectItems.java,v 1.31 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.ELException;
   44   import javax.el.ValueExpression;
   45   import javax.faces.FacesException;
   46   import javax.faces.context.FacesContext;
   47   import javax.faces.model.SelectItem;
   48   
   49   
   50   /**
   51    * <p><strong>UISelectItems</strong> is a component that may be nested
   52    * inside a {@link UISelectMany} or {@link UISelectOne} component, and
   53    * causes the addition of one or more {@link SelectItem} instances to the
   54    * list of available options in the parent component.  The
   55    * <code>value</code> of this component (set either directly, or acquired
   56    * indirectly a {@link javax.el.ValueExpression}, can be of any
   57    * of the following types:</p>
   58    * <ul>
   59    * <li><em>Single instance of {@link SelectItem}</em> - This instance is
   60    *     added to the set of available options for the parent tag.</li>
   61    * <li><em>Array of {@link SelectItem}</em> - This set of instances is
   62    *     added to the set of available options for the parent component,
   63    *     in ascending subscript order.</li>
   64    * <li><em>Collection of {@link SelectItem}</em> - This set of instances is
   65    *     added to the set of available options for the parent component,
   66    *     in the order provided by an iterator over them.</li>
   67    * <li><em>Map</em> - The keys of this object (once converted to
   68    *     Strings) are assumed to be labels, and the values of this object
   69    *     (once converted to Strings)
   70    *     are assumed to be values, of {@link SelectItem} instances that will
   71    *     be constructed dynamically and added to the set of available options
   72    *     for the parent component, in the order provided by an iterator over
   73    *     the keys.</li>
   74    * </ul>
   75    */
   76   
   77   public class UISelectItems extends UIComponentBase {
   78   
   79   
   80       // ------------------------------------------------------ Manifest Constants
   81   
   82   
   83       /**
   84        * <p>The standard component type for this component.</p>
   85        */
   86       public static final String COMPONENT_TYPE = "javax.faces.SelectItems";
   87   
   88   
   89       /**
   90        * <p>The standard component family for this component.</p>
   91        */
   92       public static final String COMPONENT_FAMILY = "javax.faces.SelectItems";
   93   
   94   
   95       // ------------------------------------------------------------ Constructors
   96   
   97   
   98       /**
   99        * <p>Create a new {@link UISelectItems} instance with default property
  100        * values.</p>
  101        */
  102       public UISelectItems() {
  103   
  104           super();
  105           setRendererType(null);
  106   
  107       }
  108   
  109   
  110       // ------------------------------------------------------ Instance Variables
  111   
  112   
  113       private Object value = null;
  114   
  115   
  116       // -------------------------------------------------------------- Properties
  117   
  118   
  119       public String getFamily() {
  120   
  121           return (COMPONENT_FAMILY);
  122   
  123       }
  124   
  125   
  126       // -------------------------------------------------- ValueHolder Properties
  127   
  128   
  129       /**
  130        * <p>Returns the <code>value</code> property of the
  131        * <code>UISelectItems</code>.</p>
  132        */
  133       public Object getValue() {
  134   
  135   	if (this.value != null) {
  136   	    return (this.value);
  137   	}
  138   	ValueExpression ve = getValueExpression("value");
  139   	if (ve != null) {
  140   	    try {
  141   		return (ve.getValue(getFacesContext().getELContext()));
  142   	    }
  143   	    catch (ELException e) {
  144   		throw new FacesException(e);
  145   	    }
  146   	} else {
  147   	    return (null);
  148   	}
  149   
  150       }
  151   
  152   
  153       /**
  154        * <p>Sets the <code>value</code> property of the
  155        * <code>UISelectItems</code>.</p>
  156        * 
  157        * @param value the new value
  158        */
  159       public void setValue(Object value) {
  160   
  161           this.value = value;
  162   
  163       }
  164   
  165   
  166       // ----------------------------------------------------- StateHolder Methods
  167   
  168   
  169       private Object[] values;
  170   
  171       public Object saveState(FacesContext context) {
  172   
  173           if (values == null) {
  174                values = new Object[2];
  175           }
  176         
  177           values[0] = super.saveState(context);
  178           values[1] = value;
  179           return (values);
  180   
  181       }
  182   
  183   
  184       public void restoreState(FacesContext context, Object state) {
  185   
  186           values = (Object[]) state;
  187           super.restoreState(context, values[0]);
  188           value = values[1];
  189   
  190       }
  191   
  192   
  193   
  194   
  195   }

Save This Page
Home » mojarra-1.2_09-b02-FCS-source » javax.faces.component » [javadoc | source]