Save This Page
Home » mojarra-1.2_09-b02-FCS-source » javax.faces.component » [javadoc | source]
    1   /*
    2    * $Id: UIOutput.java,v 1.54 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   
   44   import javax.el.ELException;
   45   import javax.el.ValueExpression;
   46   import javax.faces.FacesException;
   47   import javax.faces.context.FacesContext;
   48   import javax.faces.convert.Converter;
   49   
   50   
   51   
   52   /**
   53    * <p><strong>UIOutput</strong> is a {@link UIComponent} that has a
   54    * value, optionally retrieved from a model tier bean via a value
   55    * expression, that is displayed to the user.  The user cannot directly
   56    * modify the rendered value; it is for display purposes only.</p>
   57    *
   58    * <p>During the <em>Render Response</em> phase of the request processing
   59    * lifecycle, the current value of this component must be
   60    * converted to a String (if it is not already), according to the following
   61    * rules:</p>
   62    * <ul>
   63    * <li>If the current value is not <code>null</code>, and is not already
   64    *     a <code>String</code>, locate a {@link Converter} (if any) to use
   65    *     for the conversion, as follows:
   66    *     <ul>
   67    *     <li>If <code>getConverter()</code> returns a non-null {@link Converter},
   68    *         use that one, otherwise</li>
   69    *     <li>If <code>Application.createConverter(Class)</code>, passing the
   70    *         current value's class, returns a non-null {@link Converter},
   71    *         use that one.</li>
   72    *     </ul></li>
   73    * <li>If the current value is not <code>null</code> and a {@link Converter}
   74    *     was located, call its <code>getAsString()</code> method to perform
   75    *     the conversion.</li>
   76    * <li>If the current value is not <code>null</code> but no {@link Converter}
   77    *     was located, call <code>toString()</code> on the current value to perform
   78    *     the conversion.</li>
   79    * </ul>
   80    *
   81    * <p>By default, the <code>rendererType</code> property must be set to
   82    * "<code>javax.faces.Text</code>".  This value can be changed by calling the
   83    * <code>setRendererType()</code> method.</p>
   84    */
   85   
   86   public class UIOutput extends UIComponentBase
   87       implements ValueHolder {
   88   
   89   
   90       // ------------------------------------------------------ Manifest Constants
   91   
   92   
   93       /**
   94        * <p>The standard component type for this component.</p>
   95        */
   96       public static final String COMPONENT_TYPE = "javax.faces.Output";
   97   
   98   
   99       /**
  100        * <p>The standard component family for this component.</p>
  101        */
  102       public static final String COMPONENT_FAMILY = "javax.faces.Output";
  103   
  104   
  105       // ------------------------------------------------------------ Constructors
  106   
  107   
  108       /**
  109        * <p>Create a new {@link UIOutput} instance with default property
  110        * values.</p>
  111        */
  112       public UIOutput() {
  113   
  114           super();
  115           setRendererType("javax.faces.Text");
  116   
  117       }
  118   
  119   
  120       // ------------------------------------------------------ Instance Variables
  121   
  122   
  123       private Converter converter = null;
  124       private Object value = null;
  125   
  126   
  127   
  128       // -------------------------------------------------------------- Properties
  129   
  130   
  131       public String getFamily() {
  132   
  133           return (COMPONENT_FAMILY);
  134   
  135       }
  136   
  137   
  138       // --------------------------------------- ConvertibleValueHolder Properties
  139   
  140   
  141       public Converter getConverter() {
  142   
  143   	if (this.converter != null) {
  144   	    return (this.converter);
  145   	}
  146   	ValueExpression ve = getValueExpression("converter");
  147   	if (ve != null) {
  148   	    try {
  149   		return ((Converter) ve.getValue(getFacesContext().getELContext()));
  150   	    }
  151   	    catch (ELException e) {
  152   		throw new FacesException(e);
  153   	    }
  154   	} else {
  155   	    return (null);
  156   	}
  157   
  158       }
  159   
  160   
  161       public void setConverter(Converter converter) {
  162   
  163           this.converter = converter;
  164   
  165       }
  166   
  167   
  168   
  169       public Object getLocalValue() {
  170   
  171   	return (this.value);
  172   
  173       }
  174   
  175   
  176       public Object getValue() {
  177   
  178   	if (this.value != null) {
  179   	    return (this.value);
  180   	}
  181   	ValueExpression ve = getValueExpression("value");
  182   	if (ve != null) {
  183   	    try {
  184   		return (ve.getValue(getFacesContext().getELContext()));
  185   	    }
  186   	    catch (ELException e) {
  187   		throw new FacesException(e);
  188   	    }
  189   	} else {
  190   	    return (null);
  191   	}
  192   
  193       }
  194   
  195   
  196       public void setValue(Object value) {
  197   
  198           this.value = value;
  199   
  200       }
  201   
  202   
  203       // ----------------------------------------------------- StateHolder Methods
  204   
  205   
  206       private Object[] values;
  207   
  208       public Object saveState(FacesContext context) {
  209   
  210           if (values == null) {
  211                values = new Object[3];
  212           }
  213          
  214           values[0] = super.saveState(context);
  215           values[1] = saveAttachedState(context, converter);
  216           values[2] = value;
  217           return (values);
  218   
  219       }
  220   
  221   
  222       public void restoreState(FacesContext context, Object state) {
  223   
  224           values = (Object[]) state;
  225           super.restoreState(context, values[0]);
  226           converter = (Converter) restoreAttachedState(context, values[1]);
  227           value = values[2];
  228   
  229       }
  230   
  231   
  232   }

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